Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / chromedriver / session_unittest.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/test/chromedriver/chrome/status.h"
9 #include "chrome/test/chromedriver/chrome/stub_chrome.h"
10 #include "chrome/test/chromedriver/chrome/stub_web_view.h"
11 #include "chrome/test/chromedriver/session.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace {
15
16 class MockChrome : public StubChrome {
17  public:
18   MockChrome() : web_view_("1") {}
19   ~MockChrome() override {}
20
21   Status GetWebViewById(const std::string& id, WebView** web_view) override {
22     if (id == web_view_.GetId()) {
23       *web_view = &web_view_;
24       return Status(kOk);
25     }
26     return Status(kUnknownError);
27   }
28
29  private:
30   StubWebView web_view_;
31 };
32
33 }  // namespace
34
35 TEST(Session, GetTargetWindowNoChrome) {
36   Session session("1");
37   WebView* web_view;
38   ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
39 }
40
41 TEST(Session, GetTargetWindowTargetWindowClosed) {
42   scoped_ptr<Chrome> chrome(new MockChrome());
43   Session session("1", chrome.Pass());
44   session.window = "2";
45   WebView* web_view;
46   ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
47 }
48
49 TEST(Session, GetTargetWindowTargetWindowStillOpen) {
50   scoped_ptr<Chrome> chrome(new MockChrome());
51   Session session("1", chrome.Pass());
52   session.window = "1";
53   WebView* web_view = NULL;
54   ASSERT_EQ(kOk, session.GetTargetWindow(&web_view).code());
55   ASSERT_TRUE(web_view);
56 }
57
58 TEST(Session, SwitchToParentFrame) {
59   scoped_ptr<Chrome> chrome(new MockChrome());
60   Session session("1", chrome.Pass());
61
62   // Initial frame should be top frame.
63   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
64
65   // Switching to parent frame should be a no-op.
66   session.SwitchToParentFrame();
67   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
68
69   session.SwitchToSubFrame("1.1", std::string());
70   ASSERT_EQ("1.1", session.GetCurrentFrameId());
71   session.SwitchToParentFrame();
72   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
73
74   session.SwitchToSubFrame("2.1", std::string());
75   ASSERT_EQ("2.1", session.GetCurrentFrameId());
76   session.SwitchToSubFrame("2.2", std::string());
77   ASSERT_EQ("2.2", session.GetCurrentFrameId());
78   session.SwitchToParentFrame();
79   ASSERT_EQ("2.1", session.GetCurrentFrameId());
80   session.SwitchToParentFrame();
81   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
82 }
83
84 TEST(Session, SwitchToTopFrame) {
85   scoped_ptr<Chrome> chrome(new MockChrome());
86   Session session("1", chrome.Pass());
87
88   // Initial frame should be top frame.
89   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
90
91   // Switching to top frame should be a no-op.
92   session.SwitchToTopFrame();
93   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
94
95   session.SwitchToSubFrame("3.1", std::string());
96   ASSERT_EQ("3.1", session.GetCurrentFrameId());
97   session.SwitchToSubFrame("3.2", std::string());
98   ASSERT_EQ("3.2", session.GetCurrentFrameId());
99   session.SwitchToTopFrame();
100   ASSERT_EQ(std::string(), session.GetCurrentFrameId());
101 }