| OLD | NEW | 
|---|
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 119       "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})" | 119       "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})" | 
| 120       "  .then(() => { domAutomationController.send('Success'); }," | 120       "  .then(() => { domAutomationController.send('Success'); }," | 
| 121       "        reason => {" | 121       "        reason => {" | 
| 122       "      domAutomationController.send(reason.name + ': ' + reason.message);" | 122       "      domAutomationController.send(reason.name + ': ' + reason.message);" | 
| 123       "  });", | 123       "  });", | 
| 124       &rejection)); | 124       &rejection)); | 
| 125   EXPECT_THAT(rejection, | 125   EXPECT_THAT(rejection, | 
| 126               testing::MatchesRegex("NotFoundError: .*globally disabled.*")); | 126               testing::MatchesRegex("NotFoundError: .*globally disabled.*")); | 
| 127 } | 127 } | 
| 128 | 128 | 
| 129 // Tests that using Finch field trial parameters for blacklist additions has | 129 // Tests that using Finch field trial parameters for blocklist additions has | 
| 130 // the effect of rejecting requestDevice calls. | 130 // the effect of rejecting requestDevice calls. | 
| 131 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlacklistShouldBlock) { | 131 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlocklistShouldBlock) { | 
| 132   // Fake the BluetoothAdapter to say it's present. | 132   // Fake the BluetoothAdapter to say it's present. | 
| 133   scoped_refptr<device::MockBluetoothAdapter> adapter = | 133   scoped_refptr<device::MockBluetoothAdapter> adapter = | 
| 134       new testing::NiceMock<device::MockBluetoothAdapter>; | 134       new testing::NiceMock<device::MockBluetoothAdapter>; | 
| 135   EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true)); | 135   EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true)); | 
| 136   device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); | 136   device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); | 
| 137 | 137 | 
| 138   if (base::FieldTrialList::TrialExists("WebBluetoothBlacklist")) { | 138   if (base::FieldTrialList::TrialExists("WebBluetoothBlocklist")) { | 
| 139     LOG(INFO) << "WebBluetoothBlacklist field trial already configured."; | 139     LOG(INFO) << "WebBluetoothBlocklist field trial already configured."; | 
| 140     ASSERT_NE(variations::GetVariationParamValue("WebBluetoothBlacklist", | 140     ASSERT_NE(variations::GetVariationParamValue("WebBluetoothBlocklist", | 
| 141                                                  "blacklist_additions") | 141                                                  "blocklist_additions") | 
| 142                   .find("ed5f25a4"), | 142                   .find("ed5f25a4"), | 
| 143               std::string::npos) | 143               std::string::npos) | 
| 144         << "ERROR: WebBluetoothBlacklist field trial being tested in\n" | 144         << "ERROR: WebBluetoothBlocklist field trial being tested in\n" | 
| 145            "testing/variations/fieldtrial_testing_config_*.json must\n" | 145            "testing/variations/fieldtrial_testing_config_*.json must\n" | 
| 146            "include this test's random UUID 'ed5f25a4' in\n" | 146            "include this test's random UUID 'ed5f25a4' in\n" | 
| 147            "blacklist_additions.\n"; | 147            "blocklist_additions.\n"; | 
| 148   } else { | 148   } else { | 
| 149     LOG(INFO) << "Creating WebBluetoothBlacklist field trial for test."; | 149     LOG(INFO) << "Creating WebBluetoothBlocklist field trial for test."; | 
| 150     // Create a field trial with test parameter. | 150     // Create a field trial with test parameter. | 
| 151     std::map<std::string, std::string> params; | 151     std::map<std::string, std::string> params; | 
| 152     params["blacklist_additions"] = "ed5f25a4:e"; | 152     params["blocklist_additions"] = "ed5f25a4:e"; | 
| 153     variations::AssociateVariationParams("WebBluetoothBlacklist", "TestGroup", | 153     variations::AssociateVariationParams("WebBluetoothBlocklist", "TestGroup", | 
| 154                                          params); | 154                                          params); | 
| 155     base::FieldTrialList::CreateFieldTrial("WebBluetoothBlacklist", | 155     base::FieldTrialList::CreateFieldTrial("WebBluetoothBlocklist", | 
| 156                                            "TestGroup"); | 156                                            "TestGroup"); | 
| 157   } | 157   } | 
| 158 | 158 | 
| 159   std::string rejection; | 159   std::string rejection; | 
| 160   EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 160   EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 
| 161       web_contents_, | 161       web_contents_, | 
| 162       "navigator.bluetooth.requestDevice({filters: [{services: [0xed5f25a4]}]})" | 162       "navigator.bluetooth.requestDevice({filters: [{services: [0xed5f25a4]}]})" | 
| 163       "  .then(() => { domAutomationController.send('Success'); }," | 163       "  .then(() => { domAutomationController.send('Success'); }," | 
| 164       "        reason => {" | 164       "        reason => {" | 
| 165       "      domAutomationController.send(reason.name + ': ' + reason.message);" | 165       "      domAutomationController.send(reason.name + ': ' + reason.message);" | 
| 166       "  });", | 166       "  });", | 
| 167       &rejection)); | 167       &rejection)); | 
| 168   EXPECT_THAT(rejection, | 168   EXPECT_THAT(rejection, | 
| 169               testing::MatchesRegex("SecurityError: .*blacklisted UUID.*")); | 169               testing::MatchesRegex("SecurityError: .*blocklisted UUID.*")); | 
| 170 } | 170 } | 
| 171 | 171 | 
| 172 }  // namespace | 172 }  // namespace | 
| OLD | NEW | 
|---|