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

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

Issue 11444020: DIAL extension API skeleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: abc.... Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
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 "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 using extensions::DialDeviceData;
16 using extensions::Extension;
17
18 namespace api = extensions::api;
19
20 namespace {
21
22 class DialAPITest : public ExtensionApiTest {
23 public:
24 DialAPITest() {}
25
26 virtual void SetUpCommandLine(CommandLine* command_line) {
27 ExtensionApiTest::SetUpCommandLine(command_line);
28 command_line->AppendSwitchASCII(
29 switches::kWhitelistedExtensionID, "ddchlicdkolnonkihahngkmmmjnjlkkf");
30 }
31 };
32
33 } // namespace
34
35 // Test receiving DIAL API events.
36 IN_PROC_BROWSER_TEST_F(DialAPITest, DeviceEvents) {
37 scoped_refptr<extensions::DialAPI> api =
38 extensions::DialAPIFactory::GetInstance()->GetForProfile(profile());
39 ASSERT_TRUE(api.get());
40
41 // Make sure we get device data.
42 ResultCatcher catcher;
43 catcher.RestrictToProfile(browser()->profile());
44
45 ExtensionTestMessageListener listener("ready", true);
46 ExtensionTestMessageListener listener2("setup", true);
47
48 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("dial/experimental")));
49 EXPECT_TRUE(listener.WaitUntilSatisfied());
50
51 listener.Reply("setup");
52 listener2.WaitUntilSatisfied();
53
54 extensions::DialRegistry::DeviceList devices;
55
56 DialDeviceData device1;
57 device1.set_device_id("1");
58 device1.set_label("1");
59 device1.set_device_description_url("http://1");
60
61 devices.push_back(device1);
62 api->SendEventOnUIThread(devices);
63
64 DialDeviceData device2;
65 device2.set_device_id("2");
66 device2.set_label("2");
67 device2.set_device_description_url("http://2");
68
69 devices.push_back(device2);
70 api->SendEventOnUIThread(devices);
71
72 DialDeviceData device3;
73 device3.set_device_id("3");
74 device3.set_label("3");
75 device3.set_device_description_url("http://3");
76
77 devices.push_back(device3);
78 api->SendEventOnUIThread(devices);
79
80 listener2.Reply("go");
81
82 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
83 }
84
85 // Test discoverNow fails if there are no listeners. When there are no listeners
86 // the DIAL API will not be active.
87 IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) {
88 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "discovery.html"));
89 }
90
91 // Make sure this API is only accessible to whitelisted extensions.
92 IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) {
93 ResultCatcher catcher;
94 catcher.RestrictToProfile(browser()->profile());
95
96 ExtensionTestMessageListener listener("ready", true);
97 const extensions::Extension* extension = LoadExtensionWithFlags(
98 test_data_dir_.AppendASCII("dial/whitelist"),
99 ExtensionBrowserTest::kFlagIgnoreManifestWarnings);
100 // We should have a DIAL API not available warning.
101 ASSERT_FALSE(extension->install_warnings().empty());
102
103 EXPECT_TRUE(listener.WaitUntilSatisfied());
104
105 listener.Reply("go");
106 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
107 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/dial/dial_api_factory.cc ('k') | chrome/browser/extensions/api/dial/dial_device_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698