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

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: fix nits 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, "hkepelnjfcpenkjhgaogohaincpiobgk");
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 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("dial/experimental")));
47 EXPECT_TRUE(listener.WaitUntilSatisfied());
48
49 extensions::DialRegistry::DeviceList devices;
50
51 DialDeviceData device1;
52 device1.set_device_id("1");
53 device1.set_label("1");
54 device1.set_device_description_url("http://1");
55
56 devices.push_back(device1);
57 api->SendEventOnUIThread(devices);
58
59 DialDeviceData device2;
60 device2.set_device_id("2");
61 device2.set_label("2");
62 device2.set_device_description_url("http://2");
63
64 devices.push_back(device2);
65 api->SendEventOnUIThread(devices);
66
67 DialDeviceData device3;
68 device3.set_device_id("3");
69 device3.set_label("3");
70 device3.set_device_description_url("http://3");
71
72 devices.push_back(device3);
73 api->SendEventOnUIThread(devices);
74
75 listener.Reply("events");
76
77 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
78 }
79
80 // Test discoverNow fails if there are no listeners. When there are no listeners
81 // the DIAL API will not be active.
82 IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) {
83 ResultCatcher catcher;
84 catcher.RestrictToProfile(browser()->profile());
85
86 ExtensionTestMessageListener listener("ready", true);
87 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("dial/experimental")));
88 EXPECT_TRUE(listener.WaitUntilSatisfied());
89
90 listener.Reply("discovery");
91
92 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
93 }
94
95 // Make sure this API is only accessible to whitelisted extensions.
96 IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) {
97 ResultCatcher catcher;
98 catcher.RestrictToProfile(browser()->profile());
99
100 ExtensionTestMessageListener listener("ready", true);
101 const extensions::Extension* extension = LoadExtensionWithFlags(
102 test_data_dir_.AppendASCII("dial/whitelist"),
103 ExtensionBrowserTest::kFlagIgnoreManifestWarnings);
104 // We should have a DIAL API not available warning.
105 ASSERT_FALSE(extension->install_warnings().empty());
106
107 EXPECT_TRUE(listener.WaitUntilSatisfied());
108
109 listener.Reply("go");
110 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698