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

Unified Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc

Issue 20070002: Demo UI for device discovery and registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc
diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0f16c65d264d3490578934b484b3da04c6eaf26f
--- /dev/null
+++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc
@@ -0,0 +1,132 @@
+// Copyright 2013 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 "base/bind.h"
+#include "base/command_line.h"
Dan Beam 2013/08/12 22:33:52 base/message_loop/message_loop.h
+#include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/ui_test_utils.cc"
+
+namespace local_discovery {
+
+namespace {
+const char kChromeDevicesPage[] = "chrome://devices";
+const char kSampleServiceName[] = "myService._privet._tcp.local";
+const char kSampleDeviceID[] = "MyFakeID";
+const char kSampleDeviceHost[] = "myservice.local";
+}
+
+TestMessageLoopCondition::TestMessageLoopCondition() : set_(false),
+ waiting_(false) {
+}
+
+TestMessageLoopCondition::~TestMessageLoopCondition() {
+}
+
+void TestMessageLoopCondition::Signal() {
+ set_ = true;
+ if (waiting_) {
Dan Beam 2013/08/12 22:33:52 nit: no curlies
Noam Samuel 2013/08/12 23:25:46 Done.
+ base::MessageLoop::current()->Quit();
+ }
+}
+
+void TestMessageLoopCondition::Wait() {
+ if (!set_) {
+ waiting_ = true;
+ base::MessageLoop::current()->Run();
+ waiting_ = false;
+ }
+}
+
+FakePrivetDeviceLister::FakePrivetDeviceLister(
+ base::Closure discover_devices_called) :
+ discover_devices_called_(discover_devices_called) {
Dan Beam 2013/08/12 22:33:52 FakePrivetDeviceLister::FakePrivetDeviceLister(
Noam Samuel 2013/08/12 23:25:46 Done.
+}
+
+FakePrivetDeviceLister::~FakePrivetDeviceLister() {
+}
+
+void FakePrivetDeviceLister::Start() {
+}
+
+void FakePrivetDeviceLister::DiscoverNewDevices(bool force_referesh) {
+ discover_devices_called_.Run();
+}
+
+FakeLocalDiscoveryUIFactory::FakeLocalDiscoveryUIFactory(
+ scoped_ptr<FakePrivetDeviceLister> privet_lister) {
+ owned_privet_lister_.swap(privet_lister);
Dan Beam 2013/08/12 22:33:52 nit: why not owned_privet_lister_ = privet_list
Noam Samuel 2013/08/12 23:25:46 It is used in the accessor privet_lister().
+ privet_lister_ = owned_privet_lister_.get();
+ LocalDiscoveryUIHandler::SetFactory(this);
Dan Beam 2013/08/12 22:33:52 indent off
+}
+
+FakeLocalDiscoveryUIFactory::~FakeLocalDiscoveryUIFactory() {
+ LocalDiscoveryUIHandler::SetFactory(NULL);
Dan Beam 2013/08/12 22:33:52 indent off
Noam Samuel 2013/08/12 23:25:46 Done.
+}
+
+LocalDiscoveryUIHandler*
+FakeLocalDiscoveryUIFactory::CreateLocalDiscoveryUIHandler() {
+ DCHECK(owned_privet_lister_); // This factory is a one-use factory.
+ scoped_ptr<LocalDiscoveryUIHandler> handler(
+ new LocalDiscoveryUIHandler(
+ owned_privet_lister_.PassAs<PrivetDeviceLister>()));
+ privet_lister_->set_delegate(handler.get());
+ return handler.release();
+}
+
+LocalDiscoveryUITest::LocalDiscoveryUITest() {
+}
+
+LocalDiscoveryUITest::~LocalDiscoveryUITest() {
+}
+
+void LocalDiscoveryUITest::SetUpOnMainThread() {
+ WebUIBrowserTest::SetUpOnMainThread();
+
+ scoped_ptr<FakePrivetDeviceLister> fake_lister;
+ fake_lister.reset(new FakePrivetDeviceLister(
+ base::Bind(&TestMessageLoopCondition::Signal,
+ base::Unretained(&condition_devices_listed_))));
+
+ ui_factory_.reset(new FakeLocalDiscoveryUIFactory(
+ fake_lister.Pass()));
+
+ AddLibrary(base::FilePath("local_discovery_ui_test.js"));
+}
+
+void LocalDiscoveryUITest::SetUpCommandLine(CommandLine* command_line) {
+ WebUIBrowserTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(switches::kEnableDeviceDiscovery);
+}
+
+IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, EmptyTest) {
+ ui_test_utils::NavigateToURL(browser(), GURL(kChromeDevicesPage));
+ condition_devices_listed_.Wait();
+ ASSERT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkTableHasNoRows"));
Dan Beam 2013/08/12 22:33:52 nit: EXPECT_TRUE() (ASSERT_TRUE() should be used t
Noam Samuel 2013/08/12 23:25:46 Done.
+}
+
+IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) {
+ ui_test_utils::NavigateToURL(browser(), GURL(kChromeDevicesPage));
+ condition_devices_listed_.Wait();
+ DeviceDescription description;
+
+ description.id = kSampleDeviceID;
+ description.address = net::HostPortPair(kSampleDeviceHost, 8888);
+ description.ip_address.push_back(1);
+ description.ip_address.push_back(2);
+ description.ip_address.push_back(3);
+ description.ip_address.push_back(4);
+
+ ui_factory_->privet_lister()->delegate()->DeviceChanged(
+ true, kSampleServiceName, description);
+
+ ASSERT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkTableHasOneRow"));
+
+ ui_factory_->privet_lister()->delegate()->DeviceRemoved(
+ kSampleServiceName);
+
+ ASSERT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkTableHasNoRows"));
+}
+
+} // namespace local_discovery

Powered by Google App Engine
This is Rietveld 408576698