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

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

Issue 353063005: [ChromeDriver] Subscribe PerformanceLogger to CommandListener interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing unnecessary check in test 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
« no previous file with comments | « chrome/test/chromedriver/commands.cc ('k') | chrome/test/chromedriver/logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/test/chromedriver/chrome/status.h" 17 #include "chrome/test/chromedriver/chrome/status.h"
18 #include "chrome/test/chromedriver/chrome/stub_chrome.h" 18 #include "chrome/test/chromedriver/chrome/stub_chrome.h"
19 #include "chrome/test/chromedriver/chrome/stub_web_view.h" 19 #include "chrome/test/chromedriver/chrome/stub_web_view.h"
20 #include "chrome/test/chromedriver/chrome/web_view.h" 20 #include "chrome/test/chromedriver/chrome/web_view.h"
21 #include "chrome/test/chromedriver/command_listener_proxy.h"
21 #include "chrome/test/chromedriver/commands.h" 22 #include "chrome/test/chromedriver/commands.h"
22 #include "chrome/test/chromedriver/element_commands.h" 23 #include "chrome/test/chromedriver/element_commands.h"
23 #include "chrome/test/chromedriver/session.h" 24 #include "chrome/test/chromedriver/session.h"
24 #include "chrome/test/chromedriver/session_commands.h" 25 #include "chrome/test/chromedriver/session_commands.h"
25 #include "chrome/test/chromedriver/window_commands.h" 26 #include "chrome/test/chromedriver/window_commands.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/webdriver/atoms.h" 28 #include "third_party/webdriver/atoms.h"
28 29
29 namespace { 30 namespace {
30 31
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 scoped_ptr<base::Value> result; 540 scoped_ptr<base::Value> result;
540 ASSERT_EQ( 541 ASSERT_EQ(
541 kStaleElementReference, 542 kStaleElementReference,
542 ExecuteFindChildElement( 543 ExecuteFindChildElement(
543 1, &session, &web_view, element_id, params, &result).code()); 544 1, &session, &web_view, element_id, params, &result).code());
544 ASSERT_EQ( 545 ASSERT_EQ(
545 kStaleElementReference, 546 kStaleElementReference,
546 ExecuteFindChildElements( 547 ExecuteFindChildElements(
547 1, &session, &web_view, element_id, params, &result).code()); 548 1, &session, &web_view, element_id, params, &result).code());
548 } 549 }
550
551 namespace {
552
553 class MockCommandListener : public CommandListener {
554 public:
555 MockCommandListener() : called_(false) {}
556 virtual ~MockCommandListener() {}
557
558 virtual Status BeforeCommand(const std::string& command_name) OVERRIDE {
559 called_ = true;
560 EXPECT_STREQ("cmd", command_name.c_str());
561 return Status(kOk);
562 }
563
564 void VerifyCalled() {
565 EXPECT_TRUE(called_);
566 }
567
568 void VerifyNotCalled() {
569 EXPECT_FALSE(called_);
570 }
571
572 private:
573 bool called_;
574 };
575
576 Status ExecuteAddListenerToSessionCommand(
577 CommandListener* listener,
578 Session* session,
579 const base::DictionaryValue& params,
580 scoped_ptr<base::Value>* return_value) {
581 session->command_listeners.push_back(listener);
582 return Status(kOk);
583 }
584
585 Status ExecuteQuitSessionCommand(
586 Session* session,
587 const base::DictionaryValue& params,
588 scoped_ptr<base::Value>* return_value) {
589 session->quit = true;
590 return Status(kOk);
591 }
592
593 void OnSessionCommand(
594 base::RunLoop* run_loop,
595 const Status& status,
596 scoped_ptr<base::Value> value,
597 const std::string& session_id) {
598 ASSERT_EQ(kOk, status.code());
599 run_loop->Quit();
600 }
601
602 } // namespace
603
604 TEST(CommandsTest, SessionNotifiedOfCommand) {
605 SessionThreadMap map;
606 linked_ptr<base::Thread> thread(new base::Thread("1"));
607 ASSERT_TRUE(thread->Start());
608 std::string id("id");
609 thread->message_loop()->PostTask(
610 FROM_HERE,
611 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id));
612 map[id] = thread;
613
614 base::DictionaryValue params;
615 scoped_ptr<MockCommandListener> listener(new MockCommandListener());
616 CommandListenerProxy* proxy = new CommandListenerProxy(listener.get());
617 // We add |proxy| to the session instead of adding |listener| directly so that
618 // after the session is destroyed by ExecuteQuitSessionCommand, we can still
619 // verify the listener was called. The session owns and will destroy |proxy|.
620 SessionCommand cmd = base::Bind(
621 &ExecuteAddListenerToSessionCommand, proxy);
622 base::MessageLoop loop;
623 base::RunLoop run_loop_addlistener;
624
625 // |CommandListener|s are notified immediately before commands are run.
626 // Here, the command adds |listener| to the session, so |listener|
627 // should not be notified since it will not have been added yet.
628 ExecuteSessionCommand(
629 &map,
630 "cmd",
631 cmd,
632 false,
633 params,
634 id,
635 base::Bind(&OnSessionCommand,
636 &run_loop_addlistener));
637 run_loop_addlistener.Run();
638
639 listener->VerifyNotCalled();
640
641 base::RunLoop run_loop_testlistener;
642 cmd = base::Bind(
643 &ExecuteQuitSessionCommand);
644
645 // |listener| was added to |session| by ExecuteAddListenerToSessionCommand
646 // and should be notified before the next command, ExecuteQuitSessionCommand.
647 ExecuteSessionCommand(
648 &map,
649 "cmd",
650 cmd,
651 false,
652 params,
653 id,
654 base::Bind(&OnSessionCommand,
655 &run_loop_testlistener));
656 run_loop_testlistener.Run();
657
658 listener->VerifyCalled();
659 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/commands.cc ('k') | chrome/test/chromedriver/logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698