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

Side by Side Diff: chrome/browser/web_bluetooth_browsertest.cc

Issue 2314953002: bluetooth: web: Blacklist field trial test handles missing config. (Closed)
Patch Set: Created 4 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // This file contains browsertests for Web Bluetooth that depend on behavior 5 // This file contains browsertests for Web Bluetooth that depend on behavior
6 // defined in chrome/, not just in content/. 6 // defined in chrome/, not just in content/.
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/permissions/permission_context_base.h" 10 #include "chrome/browser/permissions/permission_context_base.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 // Tests that using Finch field trial parameters for blacklist additions has 126 // Tests that using Finch field trial parameters for blacklist additions has
127 // the effect of rejecting requestDevice calls. 127 // the effect of rejecting requestDevice calls.
128 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlacklistShouldBlock) { 128 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlacklistShouldBlock) {
129 // Fake the BluetoothAdapter to say it's present. 129 // Fake the BluetoothAdapter to say it's present.
130 scoped_refptr<device::MockBluetoothAdapter> adapter = 130 scoped_refptr<device::MockBluetoothAdapter> adapter =
131 new testing::NiceMock<device::MockBluetoothAdapter>; 131 new testing::NiceMock<device::MockBluetoothAdapter>;
132 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true)); 132 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true));
133 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); 133 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
134 134
135 ASSERT_TRUE(base::FieldTrialList::TrialExists("WebBluetoothBlacklist")) 135 if (base::FieldTrialList::TrialExists("WebBluetoothBlacklist")) {
136 << "ERROR: testing/variations/fieldtrial_testing_config_*.json must\n" 136 LOG(INFO) << "WebBluetoothBlacklist field trial already configured.";
137 << "include WebBluetoothBlacklist trial with the blacklist_additions\n" 137 ASSERT_NE(variations::GetVariationParamValue("WebBluetoothBlacklist",
138 << "parameter including this test's random UUID 'ed5f25a4'.\n"; 138 "blacklist_additions")
139 .find("ed5f25a4"),
140 std::string::npos)
141 << "ERROR: WebBluetoothBlacklist field trial being tested in\n"
142 "testing/variations/fieldtrial_testing_config_*.json must\n"
143 "include this test's random UUID 'ed5f25a4' in\n"
144 "blacklist_additions.\n";
145 } else {
146 LOG(INFO) << "Creating WebBluetoothBlacklist field trial for test.";
147 // Create a field trial with test parameter.
148 std::map<std::string, std::string> params;
149 params["blacklist_additions"] = "ed5f25a4:e";
150 variations::AssociateVariationParams("WebBluetoothBlacklist", "TestGroup",
151 params);
152 base::FieldTrialList::CreateFieldTrial("WebBluetoothBlacklist",
153 "TestGroup");
154 }
139 155
140 std::string rejection; 156 std::string rejection;
141 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 157 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
142 web_contents_, 158 web_contents_,
143 "navigator.bluetooth.requestDevice({filters: [{services: [0xed5f25a4]}]})" 159 "navigator.bluetooth.requestDevice({filters: [{services: [0xed5f25a4]}]})"
144 " .then(() => { domAutomationController.send('Success'); }," 160 " .then(() => { domAutomationController.send('Success'); },"
145 " reason => {" 161 " reason => {"
146 " domAutomationController.send(reason.name + ': ' + reason.message);" 162 " domAutomationController.send(reason.name + ': ' + reason.message);"
147 " });", 163 " });",
148 &rejection)); 164 &rejection));
149 EXPECT_THAT(rejection, 165 EXPECT_THAT(rejection,
150 testing::MatchesRegex("SecurityError: .*blacklisted UUID.*")); 166 testing::MatchesRegex("SecurityError: .*blacklisted UUID.*"));
151 } 167 }
152 168
153 } // namespace 169 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698