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.
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"
16 class MockChrome
: public StubChrome
{
18 MockChrome() : web_view_("1") {}
19 virtual ~MockChrome() {}
21 virtual Status
GetWebViewById(const std::string
& id
,
22 WebView
** web_view
) override
{
23 if (id
== web_view_
.GetId()) {
24 *web_view
= &web_view_
;
27 return Status(kUnknownError
);
31 StubWebView web_view_
;
36 TEST(Session
, GetTargetWindowNoChrome
) {
39 ASSERT_EQ(kNoSuchWindow
, session
.GetTargetWindow(&web_view
).code());
42 TEST(Session
, GetTargetWindowTargetWindowClosed
) {
43 scoped_ptr
<Chrome
> chrome(new MockChrome());
44 Session
session("1", chrome
.Pass());
47 ASSERT_EQ(kNoSuchWindow
, session
.GetTargetWindow(&web_view
).code());
50 TEST(Session
, GetTargetWindowTargetWindowStillOpen
) {
51 scoped_ptr
<Chrome
> chrome(new MockChrome());
52 Session
session("1", chrome
.Pass());
54 WebView
* web_view
= NULL
;
55 ASSERT_EQ(kOk
, session
.GetTargetWindow(&web_view
).code());
56 ASSERT_TRUE(web_view
);
59 TEST(Session
, SwitchToParentFrame
) {
60 scoped_ptr
<Chrome
> chrome(new MockChrome());
61 Session
session("1", chrome
.Pass());
63 // Initial frame should be top frame.
64 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
66 // Switching to parent frame should be a no-op.
67 session
.SwitchToParentFrame();
68 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
70 session
.SwitchToSubFrame("1.1", std::string());
71 ASSERT_EQ("1.1", session
.GetCurrentFrameId());
72 session
.SwitchToParentFrame();
73 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
75 session
.SwitchToSubFrame("2.1", std::string());
76 ASSERT_EQ("2.1", session
.GetCurrentFrameId());
77 session
.SwitchToSubFrame("2.2", std::string());
78 ASSERT_EQ("2.2", session
.GetCurrentFrameId());
79 session
.SwitchToParentFrame();
80 ASSERT_EQ("2.1", session
.GetCurrentFrameId());
81 session
.SwitchToParentFrame();
82 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
85 TEST(Session
, SwitchToTopFrame
) {
86 scoped_ptr
<Chrome
> chrome(new MockChrome());
87 Session
session("1", chrome
.Pass());
89 // Initial frame should be top frame.
90 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
92 // Switching to top frame should be a no-op.
93 session
.SwitchToTopFrame();
94 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());
96 session
.SwitchToSubFrame("3.1", std::string());
97 ASSERT_EQ("3.1", session
.GetCurrentFrameId());
98 session
.SwitchToSubFrame("3.2", std::string());
99 ASSERT_EQ("3.2", session
.GetCurrentFrameId());
100 session
.SwitchToTopFrame();
101 ASSERT_EQ(std::string(), session
.GetCurrentFrameId());