Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/command_line.h" | |
|
Dan Beam
2013/08/12 22:33:52
base/message_loop/message_loop.h
| |
| 7 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest .h" | |
| 8 #include "chrome/common/chrome_switches.h" | |
| 9 #include "chrome/test/base/ui_test_utils.cc" | |
| 10 | |
| 11 namespace local_discovery { | |
| 12 | |
| 13 namespace { | |
| 14 const char kChromeDevicesPage[] = "chrome://devices"; | |
| 15 const char kSampleServiceName[] = "myService._privet._tcp.local"; | |
| 16 const char kSampleDeviceID[] = "MyFakeID"; | |
| 17 const char kSampleDeviceHost[] = "myservice.local"; | |
| 18 } | |
| 19 | |
| 20 TestMessageLoopCondition::TestMessageLoopCondition() : set_(false), | |
| 21 waiting_(false) { | |
| 22 } | |
| 23 | |
| 24 TestMessageLoopCondition::~TestMessageLoopCondition() { | |
| 25 } | |
| 26 | |
| 27 void TestMessageLoopCondition::Signal() { | |
| 28 set_ = true; | |
| 29 if (waiting_) { | |
|
Dan Beam
2013/08/12 22:33:52
nit: no curlies
Noam Samuel
2013/08/12 23:25:46
Done.
| |
| 30 base::MessageLoop::current()->Quit(); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void TestMessageLoopCondition::Wait() { | |
| 35 if (!set_) { | |
| 36 waiting_ = true; | |
| 37 base::MessageLoop::current()->Run(); | |
| 38 waiting_ = false; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 FakePrivetDeviceLister::FakePrivetDeviceLister( | |
| 43 base::Closure discover_devices_called) : | |
| 44 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.
| |
| 45 } | |
| 46 | |
| 47 FakePrivetDeviceLister::~FakePrivetDeviceLister() { | |
| 48 } | |
| 49 | |
| 50 void FakePrivetDeviceLister::Start() { | |
| 51 } | |
| 52 | |
| 53 void FakePrivetDeviceLister::DiscoverNewDevices(bool force_referesh) { | |
| 54 discover_devices_called_.Run(); | |
| 55 } | |
| 56 | |
| 57 FakeLocalDiscoveryUIFactory::FakeLocalDiscoveryUIFactory( | |
| 58 scoped_ptr<FakePrivetDeviceLister> privet_lister) { | |
| 59 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().
| |
| 60 privet_lister_ = owned_privet_lister_.get(); | |
| 61 LocalDiscoveryUIHandler::SetFactory(this); | |
|
Dan Beam
2013/08/12 22:33:52
indent off
| |
| 62 } | |
| 63 | |
| 64 FakeLocalDiscoveryUIFactory::~FakeLocalDiscoveryUIFactory() { | |
| 65 LocalDiscoveryUIHandler::SetFactory(NULL); | |
|
Dan Beam
2013/08/12 22:33:52
indent off
Noam Samuel
2013/08/12 23:25:46
Done.
| |
| 66 } | |
| 67 | |
| 68 LocalDiscoveryUIHandler* | |
| 69 FakeLocalDiscoveryUIFactory::CreateLocalDiscoveryUIHandler() { | |
| 70 DCHECK(owned_privet_lister_); // This factory is a one-use factory. | |
| 71 scoped_ptr<LocalDiscoveryUIHandler> handler( | |
| 72 new LocalDiscoveryUIHandler( | |
| 73 owned_privet_lister_.PassAs<PrivetDeviceLister>())); | |
| 74 privet_lister_->set_delegate(handler.get()); | |
| 75 return handler.release(); | |
| 76 } | |
| 77 | |
| 78 LocalDiscoveryUITest::LocalDiscoveryUITest() { | |
| 79 } | |
| 80 | |
| 81 LocalDiscoveryUITest::~LocalDiscoveryUITest() { | |
| 82 } | |
| 83 | |
| 84 void LocalDiscoveryUITest::SetUpOnMainThread() { | |
| 85 WebUIBrowserTest::SetUpOnMainThread(); | |
| 86 | |
| 87 scoped_ptr<FakePrivetDeviceLister> fake_lister; | |
| 88 fake_lister.reset(new FakePrivetDeviceLister( | |
| 89 base::Bind(&TestMessageLoopCondition::Signal, | |
| 90 base::Unretained(&condition_devices_listed_)))); | |
| 91 | |
| 92 ui_factory_.reset(new FakeLocalDiscoveryUIFactory( | |
| 93 fake_lister.Pass())); | |
| 94 | |
| 95 AddLibrary(base::FilePath("local_discovery_ui_test.js")); | |
| 96 } | |
| 97 | |
| 98 void LocalDiscoveryUITest::SetUpCommandLine(CommandLine* command_line) { | |
| 99 WebUIBrowserTest::SetUpCommandLine(command_line); | |
| 100 command_line->AppendSwitch(switches::kEnableDeviceDiscovery); | |
| 101 } | |
| 102 | |
| 103 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, EmptyTest) { | |
| 104 ui_test_utils::NavigateToURL(browser(), GURL(kChromeDevicesPage)); | |
| 105 condition_devices_listed_.Wait(); | |
| 106 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.
| |
| 107 } | |
| 108 | |
| 109 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) { | |
| 110 ui_test_utils::NavigateToURL(browser(), GURL(kChromeDevicesPage)); | |
| 111 condition_devices_listed_.Wait(); | |
| 112 DeviceDescription description; | |
| 113 | |
| 114 description.id = kSampleDeviceID; | |
| 115 description.address = net::HostPortPair(kSampleDeviceHost, 8888); | |
| 116 description.ip_address.push_back(1); | |
| 117 description.ip_address.push_back(2); | |
| 118 description.ip_address.push_back(3); | |
| 119 description.ip_address.push_back(4); | |
| 120 | |
| 121 ui_factory_->privet_lister()->delegate()->DeviceChanged( | |
| 122 true, kSampleServiceName, description); | |
| 123 | |
| 124 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkTableHasOneRow")); | |
| 125 | |
| 126 ui_factory_->privet_lister()->delegate()->DeviceRemoved( | |
| 127 kSampleServiceName); | |
| 128 | |
| 129 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkTableHasNoRows")); | |
| 130 } | |
| 131 | |
| 132 } // namespace local_discovery | |
| OLD | NEW |