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

Unified Diff: chrome/test/chromedriver/session_unittest.cc

Issue 331943003: [ChromeDriver] Added CommandListener interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CommandListener now abstract; Session struct simplified Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/session_unittest.cc
diff --git a/chrome/test/chromedriver/session_unittest.cc b/chrome/test/chromedriver/session_unittest.cc
index 23fb779bd26a14b3667c4bf6837393e7300eb1dd..9d31e12d88c5386a796d203af70c39722774f24a 100644
--- a/chrome/test/chromedriver/session_unittest.cc
+++ b/chrome/test/chromedriver/session_unittest.cc
@@ -10,6 +10,7 @@
#include "chrome/test/chromedriver/chrome/stub_chrome.h"
#include "chrome/test/chromedriver/chrome/stub_web_view.h"
#include "chrome/test/chromedriver/session.h"
+#include "chrome/test/chromedriver/util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -32,6 +33,29 @@ class MockChrome : public StubChrome {
StubWebView web_view_;
};
+class MockCommandListener : public CommandListener {
+ public:
+ MockCommandListener() : called_(false) {}
+ virtual ~MockCommandListener() {}
+
+ virtual Status BeforeCommand(const std::string& command_name) OVERRIDE {
+ called_ = true;
+ EXPECT_STREQ("cmd", command_name.c_str());
+ return Status(kOk);
+ }
+
+ void VerifyCalled() {
+ EXPECT_TRUE(called_);
+ }
+
+ void VerifyNotCalled() {
+ EXPECT_FALSE(called_);
+ }
+
+ private:
+ bool called_;
+};
+
} // namespace
TEST(Session, GetTargetWindowNoChrome) {
@@ -101,3 +125,17 @@ TEST(Session, SwitchToTopFrame) {
session.SwitchToTopFrame();
ASSERT_EQ(std::string(), session.GetCurrentFrameId());
}
+
+TEST(Session, OnCommand) {
+ Session session("1");
+ // Listeners are owned by and will be destroyed by session
+ MockCommandListener* listener1 = new MockCommandListener();
+ MockCommandListener* listener2 = new MockCommandListener();
+ session.AddListener(listener1);
+ session.AddListener(listener2);
+ listener1->VerifyNotCalled();
+ listener2->VerifyNotCalled();
+ NotifySessionListenersBeforeCommand(&session, "cmd");
+ listener1->VerifyCalled();
+ listener2->VerifyCalled();
+}

Powered by Google App Engine
This is Rietveld 408576698