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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_apitest.cc

Issue 2583853004: [chrome.dial] Adds chrome.dial.fetchDeviceDecription API. (Closed)
Patch Set: Respond to lazyboy@ comments. Rebase w/namespace changes Created 3 years, 11 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "chrome/browser/extensions/api/dial/dial_api.h" 7 #include "chrome/browser/extensions/api/dial/dial_api.h"
8 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" 8 #include "chrome/browser/extensions/api/dial/dial_api_factory.h"
9 #include "chrome/browser/extensions/api/dial/dial_registry.h" 9 #include "chrome/browser/extensions/api/dial/dial_registry.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "extensions/common/switches.h" 12 #include "extensions/common/switches.h"
13 #include "extensions/test/extension_test_message_listener.h" 13 #include "extensions/test/extension_test_message_listener.h"
14 #include "extensions/test/result_catcher.h" 14 #include "extensions/test/result_catcher.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 using extensions::Extension; 18 using extensions::Extension;
19 using extensions::ResultCatcher; 19 using extensions::ResultCatcher;
20 20 using extensions::api::dial::DialDeviceData;
21 namespace dial = extensions::api::dial; 21 using extensions::api::dial::DialDeviceDescriptionData;
22 using extensions::api::dial::DialRegistry;
22 23
23 namespace { 24 namespace {
24 25
25 class DialAPITest : public ExtensionApiTest { 26 class DialAPITest : public ExtensionApiTest {
26 public: 27 public:
27 DialAPITest() {} 28 DialAPITest() {}
28 29
29 void SetUpCommandLine(base::CommandLine* command_line) override { 30 void SetUpCommandLine(base::CommandLine* command_line) override {
30 ExtensionApiTest::SetUpCommandLine(command_line); 31 ExtensionApiTest::SetUpCommandLine(command_line);
31 command_line->AppendSwitchASCII( 32 command_line->AppendSwitchASCII(
(...skipping 13 matching lines...) Expand all
45 // Test receiving DIAL API events. 46 // Test receiving DIAL API events.
46 IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) { 47 IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
47 // Setup the test. 48 // Setup the test.
48 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html")); 49 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html"));
49 50
50 // Send three device list updates. 51 // Send three device list updates.
51 scoped_refptr<extensions::DialAPI> api = 52 scoped_refptr<extensions::DialAPI> api =
52 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext( 53 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext(
53 profile()); 54 profile());
54 ASSERT_TRUE(api.get()); 55 ASSERT_TRUE(api.get());
55 dial::DialRegistry::DeviceList devices; 56 DialRegistry::DeviceList devices;
56 57
57 ResultCatcher catcher; 58 ResultCatcher catcher;
58 59
59 dial::DialDeviceData device1; 60 DialDeviceData device1;
60 device1.set_device_id("1"); 61 device1.set_device_id("1");
61 device1.set_label("1"); 62 device1.set_label("1");
62 device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml")); 63 device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml"));
63 64
64 devices.push_back(device1); 65 devices.push_back(device1);
65 api->SendEventOnUIThread(devices); 66 api->SendEventOnUIThread(devices);
66 67
67 dial::DialDeviceData device2; 68 DialDeviceData device2;
68 device2.set_device_id("2"); 69 device2.set_device_id("2");
69 device2.set_label("2"); 70 device2.set_label("2");
70 device2.set_device_description_url(GURL("http://127.0.0.2/dd.xml")); 71 device2.set_device_description_url(GURL("http://127.0.0.2/dd.xml"));
71 72
72 devices.push_back(device2); 73 devices.push_back(device2);
73 api->SendEventOnUIThread(devices); 74 api->SendEventOnUIThread(devices);
74 75
75 dial::DialDeviceData device3; 76 DialDeviceData device3;
76 device3.set_device_id("3"); 77 device3.set_device_id("3");
77 device3.set_label("3"); 78 device3.set_label("3");
78 device3.set_device_description_url(GURL("http://127.0.0.3/dd.xml")); 79 device3.set_device_description_url(GURL("http://127.0.0.3/dd.xml"));
79 80
80 devices.push_back(device3); 81 devices.push_back(device3);
81 api->SendEventOnUIThread(devices); 82 api->SendEventOnUIThread(devices);
82 83
83 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 84 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
84 } 85 }
85 86
(...skipping 22 matching lines...) Expand all
108 109
109 EXPECT_TRUE(listener.WaitUntilSatisfied()); 110 EXPECT_TRUE(listener.WaitUntilSatisfied());
110 111
111 listener.Reply("go"); 112 listener.Reply("go");
112 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 113 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
113 } 114 }
114 115
115 IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) { 116 IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) {
116 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html")); 117 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html"));
117 } 118 }
119
120 IN_PROC_BROWSER_TEST_F(DialAPITest, FetchDeviceDescription) {
121 scoped_refptr<extensions::DialAPI> api =
122 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext(
123 profile());
124 ASSERT_TRUE(api.get());
Wez 2017/01/05 22:29:24 nit: Omit .get() when testing a ptr as bool.
mark a. foltz 2017/01/09 21:38:08 Done.
125
126 DialDeviceData test_device("testDeviceId",
127 GURL("http://127.0.0.1/description.xml"),
128 base::Time::Now());
129 test_device.set_label("testDevice");
130
131 DialDeviceDescriptionData test_description("<xml>testDescription</xml>",
132 GURL("http://127.0.0.1/apps"));
133 api->SetDeviceForTest(test_device, test_description);
134
135 ASSERT_TRUE(RunExtensionSubtest("dial/experimental",
136 "fetch_device_description.html"));
Wez 2017/01/05 22:29:24 nit: Do we have any test cases for the API failing
mark a. foltz 2017/01/09 21:38:08 Added one.
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698