Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / dial / dial_apitest.cc
blobc4f20f1b6c90749c6ef632bf64dd1ac8a7181494
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "chrome/browser/extensions/api/dial/dial_api.h"
7 #include "chrome/browser/extensions/api/dial/dial_api_factory.h"
8 #include "chrome/browser/extensions/api/dial/dial_registry.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "extensions/common/switches.h"
12 #include "extensions/test/extension_test_message_listener.h"
13 #include "extensions/test/result_catcher.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "url/gurl.h"
17 using extensions::DialDeviceData;
18 using extensions::Extension;
20 namespace api = extensions::api;
22 namespace {
24 class DialAPITest : public ExtensionApiTest {
25 public:
26 DialAPITest() {}
28 void SetUpCommandLine(base::CommandLine* command_line) override {
29 ExtensionApiTest::SetUpCommandLine(command_line);
30 command_line->AppendSwitchASCII(
31 extensions::switches::kWhitelistedExtensionID,
32 "ddchlicdkolnonkihahngkmmmjnjlkkf");
36 } // namespace
38 // http://crbug.com/177163
39 #if defined(OS_WIN) && !defined(NDEBUG)
40 #define MAYBE_DeviceListEvents DISABLED_DeviceListEvents
41 #else
42 #define MAYBE_DeviceListEvents DeviceListEvents
43 #endif
44 // Test receiving DIAL API events.
45 IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
46 // Setup the test.
47 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html"));
49 // Send three device list updates.
50 scoped_refptr<extensions::DialAPI> api =
51 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext(
52 profile());
53 ASSERT_TRUE(api.get());
54 extensions::DialRegistry::DeviceList devices;
56 extensions::ResultCatcher catcher;
58 DialDeviceData device1;
59 device1.set_device_id("1");
60 device1.set_label("1");
61 device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml"));
63 devices.push_back(device1);
64 api->SendEventOnUIThread(devices);
66 DialDeviceData device2;
67 device2.set_device_id("2");
68 device2.set_label("2");
69 device2.set_device_description_url(GURL("http://127.0.0.2/dd.xml"));
71 devices.push_back(device2);
72 api->SendEventOnUIThread(devices);
74 DialDeviceData device3;
75 device3.set_device_id("3");
76 device3.set_label("3");
77 device3.set_device_description_url(GURL("http://127.0.0.3/dd.xml"));
79 devices.push_back(device3);
80 api->SendEventOnUIThread(devices);
82 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
85 IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) {
86 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "discovery.html"));
89 // discoverNow does not do discovery when there are no listeners; in that case
90 // the DIAL service will not be active.
91 IN_PROC_BROWSER_TEST_F(DialAPITest, DiscoveryNoListeners) {
92 ASSERT_TRUE(RunExtensionSubtest("dial/experimental",
93 "discovery_no_listeners.html"));
96 // Make sure this API is only accessible to whitelisted extensions.
97 IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) {
98 extensions::ResultCatcher catcher;
99 catcher.RestrictToBrowserContext(browser()->profile());
101 ExtensionTestMessageListener listener("ready", true);
102 const extensions::Extension* extension = LoadExtensionWithFlags(
103 test_data_dir_.AppendASCII("dial/whitelist"),
104 ExtensionBrowserTest::kFlagIgnoreManifestWarnings);
105 // We should have a DIAL API not available warning.
106 ASSERT_FALSE(extension->install_warnings().empty());
108 EXPECT_TRUE(listener.WaitUntilSatisfied());
110 listener.Reply("go");
111 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
114 IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) {
115 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html"));