Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: chrome/test/chromedriver/session_unittest.cc

Issue 353063005: [ChromeDriver] Subscribe PerformanceLogger to CommandListener interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unintentional debug output Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/test/chromedriver/chrome/stub_web_view.h" 11 #include "chrome/test/chromedriver/chrome/stub_web_view.h"
12 #include "chrome/test/chromedriver/session.h" 12 #include "chrome/test/chromedriver/session.h"
13 #include "chrome/test/chromedriver/util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 class MockChrome : public StubChrome { 18 class MockChrome : public StubChrome {
18 public: 19 public:
19 MockChrome() : web_view_("1") {} 20 MockChrome() : web_view_("1") {}
20 virtual ~MockChrome() {} 21 virtual ~MockChrome() {}
21 22
22 virtual Status GetWebViewById(const std::string& id, 23 virtual Status GetWebViewById(const std::string& id,
23 WebView** web_view) OVERRIDE { 24 WebView** web_view) OVERRIDE {
24 if (id == web_view_.GetId()) { 25 if (id == web_view_.GetId()) {
25 *web_view = &web_view_; 26 *web_view = &web_view_;
26 return Status(kOk); 27 return Status(kOk);
27 } 28 }
28 return Status(kUnknownError); 29 return Status(kUnknownError);
29 } 30 }
30 31
31 private: 32 private:
32 StubWebView web_view_; 33 StubWebView web_view_;
33 }; 34 };
34 35
36 class MockCommandListener : public CommandListener {
stgao 2014/07/01 19:02:27 Duplicate code again. Now it seems that it should
johnmoore 2014/07/02 22:17:45 I have removed AddListener from session, so this d
37 public:
38 MockCommandListener() : called_(false) {}
39 virtual ~MockCommandListener() {}
40
41 virtual Status BeforeCommand(const std::string& command_name) OVERRIDE {
42 called_ = true;
43 EXPECT_STREQ("cmd", command_name.c_str());
44 return Status(kOk);
45 }
46
47 void VerifyCalled() {
48 EXPECT_TRUE(called_);
49 }
50
51 void VerifyNotCalled() {
52 EXPECT_FALSE(called_);
53 }
54
55 private:
56 bool called_;
57 };
58
35 } // namespace 59 } // namespace
36 60
37 TEST(Session, GetTargetWindowNoChrome) { 61 TEST(Session, GetTargetWindowNoChrome) {
38 Session session("1"); 62 Session session("1");
39 WebView* web_view; 63 WebView* web_view;
40 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); 64 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
41 } 65 }
42 66
43 TEST(Session, GetTargetWindowTargetWindowClosed) { 67 TEST(Session, GetTargetWindowTargetWindowClosed) {
44 scoped_ptr<Chrome> chrome(new MockChrome()); 68 scoped_ptr<Chrome> chrome(new MockChrome());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 session.SwitchToTopFrame(); 118 session.SwitchToTopFrame();
95 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); 119 ASSERT_EQ(std::string(), session.GetCurrentFrameId());
96 120
97 session.SwitchToSubFrame("3.1", std::string()); 121 session.SwitchToSubFrame("3.1", std::string());
98 ASSERT_EQ("3.1", session.GetCurrentFrameId()); 122 ASSERT_EQ("3.1", session.GetCurrentFrameId());
99 session.SwitchToSubFrame("3.2", std::string()); 123 session.SwitchToSubFrame("3.2", std::string());
100 ASSERT_EQ("3.2", session.GetCurrentFrameId()); 124 ASSERT_EQ("3.2", session.GetCurrentFrameId());
101 session.SwitchToTopFrame(); 125 session.SwitchToTopFrame();
102 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); 126 ASSERT_EQ(std::string(), session.GetCurrentFrameId());
103 } 127 }
128
129 TEST(Session, OnCommand) {
130 Session session("1");
131 // Listeners are owned by and will be destroyed by session
132 MockCommandListener* listener1 = new MockCommandListener();
133 MockCommandListener* listener2 = new MockCommandListener();
134 session.AddListener(listener1);
135 session.AddListener(listener2);
136 listener1->VerifyNotCalled();
137 listener2->VerifyNotCalled();
138 NotifySessionListenersBeforeCommand(&session, "cmd");
139 listener1->VerifyCalled();
140 listener2->VerifyCalled();
141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698