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