blob: dd83e353d7661111492b79118369725f599e4672 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "chrome/browser/extensions/api/dial/dial_api.h"
#include "chrome/browser/extensions/api/dial/dial_api_factory.h"
#include "chrome/browser/extensions/api/dial/dial_registry.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/common/chrome_switches.h"
#include "googleurl/src/gurl.h"
#include "testing/gmock/include/gmock/gmock.h"
using extensions::DialDeviceData;
using extensions::Extension;
namespace api = extensions::api;
namespace {
class DialAPITest : public ExtensionApiTest {
public:
DialAPITest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(
switches::kWhitelistedExtensionID, "ddchlicdkolnonkihahngkmmmjnjlkkf");
}
};
} // namespace
// http://crbug.com/177163
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_DeviceListEvents DISABLED_DeviceListEvents
#else
#define MAYBE_DeviceListEvents DeviceListEvents
#endif
// Test receiving DIAL API events.
IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
// Setup the test.
ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "device_list.html"));
// Send three device list updates.
scoped_refptr<extensions::DialAPI> api =
extensions::DialAPIFactory::GetInstance()->GetForProfile(profile());
ASSERT_TRUE(api.get());
extensions::DialRegistry::DeviceList devices;
ResultCatcher catcher;
DialDeviceData device1;
device1.set_device_id("1");
device1.set_label("1");
device1.set_device_description_url(GURL("http://127.0.0.1/dd.xml"));
devices.push_back(device1);
api->SendEventOnUIThread(devices);
DialDeviceData device2;
device2.set_device_id("2");
device2.set_label("2");
device2.set_device_description_url(GURL("http://127.0.0.2/dd.xml"));
devices.push_back(device2);
api->SendEventOnUIThread(devices);
DialDeviceData device3;
device3.set_device_id("3");
device3.set_label("3");
device3.set_device_description_url(GURL("http://127.0.0.3/dd.xml"));
devices.push_back(device3);
api->SendEventOnUIThread(devices);
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
// Test discoverNow fails if there are no listeners. When there are no listeners
// the DIAL API will not be active.
IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) {
ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "discovery.html"));
}
// Make sure this API is only accessible to whitelisted extensions.
IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) {
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
ExtensionTestMessageListener listener("ready", true);
const extensions::Extension* extension = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("dial/whitelist"),
ExtensionBrowserTest::kFlagIgnoreManifestWarnings);
// We should have a DIAL API not available warning.
ASSERT_FALSE(extension->install_warnings().empty());
EXPECT_TRUE(listener.WaitUntilSatisfied());
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_F(DialAPITest, OnError) {
ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "on_error.html"));
}
|