| OLD | NEW |
| 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 "chrome/browser/extensions/api/dial/dial_api.h" | 6 #include "chrome/browser/extensions/api/dial/dial_api.h" |
| 7 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" | 7 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" |
| 8 #include "chrome/browser/extensions/api/dial/dial_registry.h" | 8 #include "chrome/browser/extensions/api/dial/dial_registry.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "extensions/common/switches.h" | 12 #include "extensions/common/switches.h" |
| 13 #include "extensions/test/result_catcher.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 using extensions::DialDeviceData; | 17 using extensions::DialDeviceData; |
| 17 using extensions::Extension; | 18 using extensions::Extension; |
| 18 | 19 |
| 19 namespace api = extensions::api; | 20 namespace api = extensions::api; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 // Setup the test. | 46 // Setup the test. |
| 46 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html")); | 47 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html")); |
| 47 | 48 |
| 48 // Send three device list updates. | 49 // Send three device list updates. |
| 49 scoped_refptr<extensions::DialAPI> api = | 50 scoped_refptr<extensions::DialAPI> api = |
| 50 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext( | 51 extensions::DialAPIFactory::GetInstance()->GetForBrowserContext( |
| 51 profile()); | 52 profile()); |
| 52 ASSERT_TRUE(api.get()); | 53 ASSERT_TRUE(api.get()); |
| 53 extensions::DialRegistry::DeviceList devices; | 54 extensions::DialRegistry::DeviceList devices; |
| 54 | 55 |
| 55 ResultCatcher catcher; | 56 extensions::ResultCatcher catcher; |
| 56 | 57 |
| 57 DialDeviceData device1; | 58 DialDeviceData device1; |
| 58 device1.set_device_id("1"); | 59 device1.set_device_id("1"); |
| 59 device1.set_label("1"); | 60 device1.set_label("1"); |
| 60 device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml")); | 61 device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml")); |
| 61 | 62 |
| 62 devices.push_back(device1); | 63 devices.push_back(device1); |
| 63 api->SendEventOnUIThread(devices); | 64 api->SendEventOnUIThread(devices); |
| 64 | 65 |
| 65 DialDeviceData device2; | 66 DialDeviceData device2; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 87 | 88 |
| 88 // discoverNow does not do discovery when there are no listeners; in that case | 89 // discoverNow does not do discovery when there are no listeners; in that case |
| 89 // the DIAL service will not be active. | 90 // the DIAL service will not be active. |
| 90 IN_PROC_BROWSER_TEST_F(DialAPITest, DiscoveryNoListeners) { | 91 IN_PROC_BROWSER_TEST_F(DialAPITest, DiscoveryNoListeners) { |
| 91 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", | 92 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", |
| 92 "discovery_no_listeners.html")); | 93 "discovery_no_listeners.html")); |
| 93 } | 94 } |
| 94 | 95 |
| 95 // Make sure this API is only accessible to whitelisted extensions. | 96 // Make sure this API is only accessible to whitelisted extensions. |
| 96 IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) { | 97 IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) { |
| 97 ResultCatcher catcher; | 98 extensions::ResultCatcher catcher; |
| 98 catcher.RestrictToProfile(browser()->profile()); | 99 catcher.RestrictToBrowserContext(browser()->profile()); |
| 99 | 100 |
| 100 ExtensionTestMessageListener listener("ready", true); | 101 ExtensionTestMessageListener listener("ready", true); |
| 101 const extensions::Extension* extension = LoadExtensionWithFlags( | 102 const extensions::Extension* extension = LoadExtensionWithFlags( |
| 102 test_data_dir_.AppendASCII("dial/whitelist"), | 103 test_data_dir_.AppendASCII("dial/whitelist"), |
| 103 ExtensionBrowserTest::kFlagIgnoreManifestWarnings); | 104 ExtensionBrowserTest::kFlagIgnoreManifestWarnings); |
| 104 // We should have a DIAL API not available warning. | 105 // We should have a DIAL API not available warning. |
| 105 ASSERT_FALSE(extension->install_warnings().empty()); | 106 ASSERT_FALSE(extension->install_warnings().empty()); |
| 106 | 107 |
| 107 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 108 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 108 | 109 |
| 109 listener.Reply("go"); | 110 listener.Reply("go"); |
| 110 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 111 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) { | 114 IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) { |
| 114 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html")); | 115 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html")); |
| 115 } | 116 } |
| OLD | NEW |