OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <list> | 5 #include <list> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/test/chromedriver/chrome/status.h" | 9 #include "chrome/test/chromedriver/chrome/status.h" |
10 #include "chrome/test/chromedriver/chrome/stub_chrome.h" | 10 #include "chrome/test/chromedriver/chrome/stub_chrome.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 *web_view = &web_view_; | 25 *web_view = &web_view_; |
26 return Status(kOk); | 26 return Status(kOk); |
27 } | 27 } |
28 return Status(kUnknownError); | 28 return Status(kUnknownError); |
29 } | 29 } |
30 | 30 |
31 private: | 31 private: |
32 StubWebView web_view_; | 32 StubWebView web_view_; |
33 }; | 33 }; |
34 | 34 |
35 class MockCommandListener : public CommandListener { | |
stgao
2014/06/15 23:54:41
Duplicate code as the one in commands_unittest.cc
johnmoore
2014/06/16 17:28:34
Would it make sense for the stub class to perform
| |
36 public: | |
37 MockCommandListener() : called_(false) {} | |
38 virtual ~MockCommandListener() {} | |
39 | |
40 virtual Status OnCommand(const std::string& command_name) OVERRIDE { | |
41 called_ = true; | |
42 EXPECT_STREQ("cmd", command_name.c_str()); | |
43 return Status(kOk); | |
44 } | |
45 | |
46 void VerifyCalled() { | |
47 EXPECT_TRUE(called_); | |
48 } | |
49 | |
50 void VerifyNotCalled() { | |
51 EXPECT_FALSE(called_); | |
52 } | |
53 | |
54 private: | |
55 bool called_; | |
56 }; | |
57 | |
35 } // namespace | 58 } // namespace |
36 | 59 |
37 TEST(Session, GetTargetWindowNoChrome) { | 60 TEST(Session, GetTargetWindowNoChrome) { |
38 Session session("1"); | 61 Session session("1"); |
39 WebView* web_view; | 62 WebView* web_view; |
40 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); | 63 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); |
41 } | 64 } |
42 | 65 |
43 TEST(Session, GetTargetWindowTargetWindowClosed) { | 66 TEST(Session, GetTargetWindowTargetWindowClosed) { |
44 scoped_ptr<Chrome> chrome(new MockChrome()); | 67 scoped_ptr<Chrome> chrome(new MockChrome()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 session.SwitchToTopFrame(); | 117 session.SwitchToTopFrame(); |
95 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 118 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
96 | 119 |
97 session.SwitchToSubFrame("3.1", std::string()); | 120 session.SwitchToSubFrame("3.1", std::string()); |
98 ASSERT_EQ("3.1", session.GetCurrentFrameId()); | 121 ASSERT_EQ("3.1", session.GetCurrentFrameId()); |
99 session.SwitchToSubFrame("3.2", std::string()); | 122 session.SwitchToSubFrame("3.2", std::string()); |
100 ASSERT_EQ("3.2", session.GetCurrentFrameId()); | 123 ASSERT_EQ("3.2", session.GetCurrentFrameId()); |
101 session.SwitchToTopFrame(); | 124 session.SwitchToTopFrame(); |
102 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 125 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
103 } | 126 } |
127 | |
128 TEST(Session, OnCommand) { | |
129 Session session("1"); | |
130 MockCommandListener* listener1 = new MockCommandListener(); | |
stgao
2014/06/15 23:57:38
Memory leak: please use a scoped_ptr.
johnmoore
2014/06/16 20:49:18
session.AddListener should take care of transferri
| |
131 MockCommandListener* listener2 = new MockCommandListener(); | |
132 MockCommandListener* listener3 = new MockCommandListener(); | |
133 session.AddListener(listener1); | |
134 session.AddListener(listener2); | |
135 session.AddListener(listener3); | |
136 listener1->VerifyNotCalled(); | |
137 listener2->VerifyNotCalled(); | |
138 listener3->VerifyNotCalled(); | |
139 session.OnCommand("cmd"); | |
140 listener1->VerifyCalled(); | |
141 listener2->VerifyCalled(); | |
142 listener3->VerifyCalled(); | |
143 } | |
OLD | NEW |