blob: 333bad8c9ddbcdf47b75bc49670fece5799c048c [file] [log] [blame]
juncai1da12032016-07-15 19:10:121// Copyright 2015 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
Donna Wu341df42f2018-11-02 15:18:575#include <memory>
juncai1da12032016-07-15 19:10:126#include <string>
Donna Wu341df42f2018-11-02 15:18:577#include <utility>
juncai1da12032016-07-15 19:10:128
9#include "base/macros.h"
10#include "base/strings/string16.h"
11#include "base/strings/utf_string_conversions.h"
Devlin Cronin626d80c2018-06-01 01:08:3612#include "base/test/metrics/histogram_tester.h"
Yuta Hijikata235fc62b2020-12-08 03:48:3213#include "build/chromeos_buildflags.h"
cco3dca47e22017-05-19 19:23:0114#include "chrome/browser/chromeos/profiles/profile_helper.h"
Evan Stadeea9be28f2018-02-06 18:32:3115#include "chrome/browser/notifications/notification_display_service.h"
16#include "chrome/browser/notifications/notification_display_service_tester.h"
17#include "chrome/browser/notifications/system_notification_helper.h"
cco3dca47e22017-05-19 19:23:0118#include "chrome/browser/profiles/profile_manager.h"
19#include "chrome/browser/ui/browser_list.h"
20#include "chrome/browser/ui/tabs/tab_strip_model.h"
juncai1da12032016-07-15 19:10:1221#include "chrome/browser/usb/web_usb_detector.h"
cco3dca47e22017-05-19 19:23:0122#include "chrome/test/base/browser_with_test_window_test.h"
23#include "chrome/test/base/testing_browser_process.h"
24#include "chrome/test/base/testing_profile_manager.h"
Donna Wu4dc9df32019-05-20 03:56:2125#include "services/device/public/cpp/test/fake_usb_device_info.h"
26#include "services/device/public/cpp/test/fake_usb_device_manager.h"
27#include "services/device/public/mojom/usb_device.mojom.h"
28#include "services/device/public/mojom/usb_manager.mojom.h"
juncai1da12032016-07-15 19:10:1229#include "testing/gtest/include/gtest/gtest.h"
Evan Stade889ce4712018-01-28 15:26:2630#include "ui/message_center/public/cpp/notification.h"
31#include "ui/message_center/public/cpp/notification_delegate.h"
juncai1da12032016-07-15 19:10:1232#include "url/gurl.h"
33
Yuta Hijikata235fc62b2020-12-08 03:48:3234#if BUILDFLAG(IS_CHROMEOS_ASH)
Evan Stade3a827a02019-08-16 23:13:5335#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
36#include "components/user_manager/scoped_user_manager.h"
37#include "components/user_manager/user_manager.h"
38#include "components/user_manager/user_names.h"
39#endif
40
reillygdfd32df2016-10-18 02:42:1641// These tests are disabled because WebUsbDetector::Initialize is a noop on
42// Windows due to jank and hangs caused by enumerating devices.
43// https://crbug.com/656702
44#if !defined(OS_WIN)
juncai1da12032016-07-15 19:10:1245namespace {
46
cco3dca47e22017-05-19 19:23:0147const char* kProfileName = "[email protected]";
48
juncai1da12032016-07-15 19:10:1249// USB device product name.
50const char* kProductName_1 = "Google Product A";
51const char* kProductName_2 = "Google Product B";
52const char* kProductName_3 = "Google Product C";
53
54// USB device landing page.
55const char* kLandingPage_1 = "https://www.google.com/A";
56const char* kLandingPage_2 = "https://www.google.com/B";
57const char* kLandingPage_3 = "https://www.google.com/C";
James Hollyerc59c9c42018-12-20 03:39:0658const char* kLandingPage_1_fuzzed = "https://www.google.com/A/fuzzy";
juncai1da12032016-07-15 19:10:1259
60} // namespace
61
cco3dca47e22017-05-19 19:23:0162class WebUsbDetectorTest : public BrowserWithTestWindowTest {
juncai1da12032016-07-15 19:10:1263 public:
Evan Stadeef1543f2017-11-17 20:20:1364 WebUsbDetectorTest() {}
juncai1da12032016-07-15 19:10:1265 ~WebUsbDetectorTest() override = default;
66
cco3dca47e22017-05-19 19:23:0167 TestingProfile* CreateProfile() override {
Evan Stadeef1543f2017-11-17 20:20:1368 return profile_manager()->CreateTestingProfile(kProfileName);
juncai1da12032016-07-15 19:10:1269 }
70
cco3dca47e22017-05-19 19:23:0171 void SetUp() override {
cco3dca47e22017-05-19 19:23:0172 BrowserWithTestWindowTest::SetUp();
Yuta Hijikata235fc62b2020-12-08 03:48:3273#if BUILDFLAG(IS_CHROMEOS_ASH)
Evan Stade3a827a02019-08-16 23:13:5374 user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
75 std::make_unique<chromeos::FakeChromeUserManager>());
76
77 GetFakeUserManager()->AddUser(user_manager::StubAccountId());
78 GetFakeUserManager()->LoginUser(user_manager::StubAccountId());
79
cco3dca47e22017-05-19 19:23:0180 chromeos::ProfileHelper::Get()->SetActiveUserIdForTesting(kProfileName);
81#endif
82 BrowserList::SetLastActive(browser());
Toni Barzicb598380e2018-11-26 19:14:1083 TestingBrowserProcess::GetGlobal()->SetSystemNotificationHelper(
84 std::make_unique<SystemNotificationHelper>());
Evan Stadeea9be28f2018-02-06 18:32:3185 display_service_ = std::make_unique<NotificationDisplayServiceTester>(
Toni Barzicb598380e2018-11-26 19:14:1086 nullptr /* profile */);
cco3dca47e22017-05-19 19:23:0187
88 web_usb_detector_.reset(new WebUsbDetector());
Donna Wu341df42f2018-11-02 15:18:5789 // Set a fake USB device manager before Initialize().
Miyoung Shin2dd36fa72019-08-29 03:57:0090 mojo::PendingRemote<device::mojom::UsbDeviceManager> device_manager;
91 device_manager_.AddReceiver(
92 device_manager.InitWithNewPipeAndPassReceiver());
93 web_usb_detector_->SetDeviceManagerForTesting(std::move(device_manager));
cco3dca47e22017-05-19 19:23:0194 }
95
96 void TearDown() override {
97 BrowserWithTestWindowTest::TearDown();
Yuta Hijikata235fc62b2020-12-08 03:48:3298#if BUILDFLAG(IS_CHROMEOS_ASH)
Evan Stade3a827a02019-08-16 23:13:5399 user_manager_enabler_.reset();
100#endif
101 web_usb_detector_.reset();
cco3dca47e22017-05-19 19:23:01102 }
103
104 void Initialize() { web_usb_detector_->Initialize(); }
juncai1da12032016-07-15 19:10:12105
106 protected:
Yuta Hijikata235fc62b2020-12-08 03:48:32107#if BUILDFLAG(IS_CHROMEOS_ASH)
Evan Stade3a827a02019-08-16 23:13:53108 chromeos::FakeChromeUserManager* GetFakeUserManager() {
109 return static_cast<chromeos::FakeChromeUserManager*>(
110 user_manager::UserManager::Get());
111 }
112
113 std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
114#endif
115
Donna Wu341df42f2018-11-02 15:18:57116 device::FakeUsbDeviceManager device_manager_;
Evan Stadeea9be28f2018-02-06 18:32:31117 std::unique_ptr<WebUsbDetector> web_usb_detector_;
118 std::unique_ptr<NotificationDisplayServiceTester> display_service_;
juncai1da12032016-07-15 19:10:12119
120 private:
121 DISALLOW_COPY_AND_ASSIGN(WebUsbDetectorTest);
juncai1da12032016-07-15 19:10:12122};
123
124TEST_F(WebUsbDetectorTest, UsbDeviceAddedAndRemoved) {
juncai1da12032016-07-15 19:10:12125 GURL landing_page(kLandingPage_1);
cco3dca47e22017-05-19 19:23:01126 Initialize();
Donna Wu341df42f2018-11-02 15:18:57127 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12128
Donna Wu341df42f2018-11-02 15:18:57129 auto device = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
130 0, 1, "Google", kProductName_1, "002", landing_page);
131 device_manager_.AddDevice(device);
132 base::RunLoop().RunUntilIdle();
133
Evan Stadeea9be28f2018-02-06 18:32:31134 base::Optional<message_center::Notification> notification =
Donna Wu341df42f2018-11-02 15:18:57135 display_service_->GetNotification(device->guid());
Evan Stadeea9be28f2018-02-06 18:32:31136 ASSERT_TRUE(notification);
juncai1da12032016-07-15 19:10:12137 base::string16 expected_title =
138 base::ASCIIToUTF16("Google Product A detected");
139 EXPECT_EQ(expected_title, notification->title());
140 base::string16 expected_message =
Reilly Grant85797cd2017-10-16 18:10:12141 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12142 EXPECT_EQ(expected_message, notification->message());
143 EXPECT_TRUE(notification->delegate() != nullptr);
144
Donna Wu341df42f2018-11-02 15:18:57145 device_manager_.RemoveDevice(device);
146 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31147 // Device is removed, so notification should be removed too.
Donna Wu341df42f2018-11-02 15:18:57148 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12149}
150
151TEST_F(WebUsbDetectorTest, UsbDeviceWithoutProductNameAddedAndRemoved) {
Lei Zhang9b0be802020-05-05 21:11:48152 std::string product_name;
juncai1da12032016-07-15 19:10:12153 GURL landing_page(kLandingPage_1);
cco3dca47e22017-05-19 19:23:01154 Initialize();
Donna Wu341df42f2018-11-02 15:18:57155 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12156
Donna Wu341df42f2018-11-02 15:18:57157 auto device = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
158 0, 1, "Google", product_name, "002", landing_page);
159 device_manager_.AddDevice(device);
160 base::RunLoop().RunUntilIdle();
161
juncai1da12032016-07-15 19:10:12162 // For device without product name, no notification is generated.
Donna Wu341df42f2018-11-02 15:18:57163 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12164
Donna Wu341df42f2018-11-02 15:18:57165 device_manager_.RemoveDevice(device);
166 base::RunLoop().RunUntilIdle();
167 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12168}
169
170TEST_F(WebUsbDetectorTest, UsbDeviceWithoutLandingPageAddedAndRemoved) {
171 GURL landing_page("");
cco3dca47e22017-05-19 19:23:01172 Initialize();
Donna Wu341df42f2018-11-02 15:18:57173 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12174
Donna Wu341df42f2018-11-02 15:18:57175 auto device = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
176 0, 1, "Google", kProductName_1, "002", landing_page);
177 device_manager_.AddDevice(device);
178 base::RunLoop().RunUntilIdle();
179
juncai1da12032016-07-15 19:10:12180 // For device without landing page, no notification is generated.
Donna Wu341df42f2018-11-02 15:18:57181 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12182
Donna Wu341df42f2018-11-02 15:18:57183 device_manager_.RemoveDevice(device);
184 base::RunLoop().RunUntilIdle();
185 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12186}
187
188TEST_F(WebUsbDetectorTest, UsbDeviceWasThereBeforeAndThenRemoved) {
189 GURL landing_page(kLandingPage_1);
juncai1da12032016-07-15 19:10:12190
191 // USB device was added before web_usb_detector was created.
Donna Wu341df42f2018-11-02 15:18:57192 auto device = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
193 0, 1, "Google", kProductName_1, "002", landing_page);
194 device_manager_.AddDevice(device);
195 base::RunLoop().RunUntilIdle();
196
197 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12198
cco3dca47e22017-05-19 19:23:01199 Initialize();
Donna Wu341df42f2018-11-02 15:18:57200 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12201
Donna Wu341df42f2018-11-02 15:18:57202 device_manager_.RemoveDevice(device);
203 base::RunLoop().RunUntilIdle();
204 EXPECT_FALSE(display_service_->GetNotification(device->guid()));
juncai1da12032016-07-15 19:10:12205}
206
207TEST_F(
208 WebUsbDetectorTest,
209 ThreeUsbDevicesWereThereBeforeAndThenRemovedBeforeWebUsbDetectorWasCreated) {
juncai1da12032016-07-15 19:10:12210 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57211 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
212 0, 1, "Google", kProductName_1, "002", landing_page_1);
juncai1da12032016-07-15 19:10:12213 std::string guid_1 = device_1->guid();
214
juncai1da12032016-07-15 19:10:12215 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57216 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
217 3, 4, "Google", kProductName_2, "005", landing_page_2);
juncai1da12032016-07-15 19:10:12218 std::string guid_2 = device_2->guid();
219
juncai1da12032016-07-15 19:10:12220 GURL landing_page_3(kLandingPage_3);
Donna Wu341df42f2018-11-02 15:18:57221 auto device_3 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
222 6, 7, "Google", kProductName_3, "008", landing_page_3);
juncai1da12032016-07-15 19:10:12223 std::string guid_3 = device_3->guid();
224
225 // Three usb devices were added and removed before web_usb_detector was
226 // created.
Donna Wu341df42f2018-11-02 15:18:57227 device_manager_.AddDevice(device_1);
228 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31229 EXPECT_FALSE(display_service_->GetNotification(guid_1));
Donna Wu341df42f2018-11-02 15:18:57230
231 device_manager_.AddDevice(device_2);
232 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31233 EXPECT_FALSE(display_service_->GetNotification(guid_2));
Donna Wu341df42f2018-11-02 15:18:57234
235 device_manager_.AddDevice(device_3);
236 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31237 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12238
Donna Wu341df42f2018-11-02 15:18:57239 device_manager_.RemoveDevice(device_1);
240 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31241 EXPECT_FALSE(display_service_->GetNotification(guid_1));
Donna Wu341df42f2018-11-02 15:18:57242
243 device_manager_.RemoveDevice(device_2);
244 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31245 EXPECT_FALSE(display_service_->GetNotification(guid_2));
Donna Wu341df42f2018-11-02 15:18:57246
247 device_manager_.RemoveDevice(device_3);
248 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31249 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12250
Donna Wu341df42f2018-11-02 15:18:57251 Initialize();
252 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12253}
254
255TEST_F(
256 WebUsbDetectorTest,
257 ThreeUsbDevicesWereThereBeforeAndThenRemovedAfterWebUsbDetectorWasCreated) {
juncai1da12032016-07-15 19:10:12258 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57259 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
260 0, 1, "Google", kProductName_1, "002", landing_page_1);
juncai1da12032016-07-15 19:10:12261 std::string guid_1 = device_1->guid();
262
juncai1da12032016-07-15 19:10:12263 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57264 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
265 3, 4, "Google", kProductName_2, "005", landing_page_2);
juncai1da12032016-07-15 19:10:12266 std::string guid_2 = device_2->guid();
267
juncai1da12032016-07-15 19:10:12268 GURL landing_page_3(kLandingPage_3);
Donna Wu341df42f2018-11-02 15:18:57269 auto device_3 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
270 6, 7, "Google", kProductName_3, "008", landing_page_3);
juncai1da12032016-07-15 19:10:12271 std::string guid_3 = device_3->guid();
272
273 // Three usb devices were added before web_usb_detector was created.
Donna Wu341df42f2018-11-02 15:18:57274 device_manager_.AddDevice(device_1);
275 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31276 EXPECT_FALSE(display_service_->GetNotification(guid_1));
Donna Wu341df42f2018-11-02 15:18:57277
278 device_manager_.AddDevice(device_2);
279 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31280 EXPECT_FALSE(display_service_->GetNotification(guid_2));
Donna Wu341df42f2018-11-02 15:18:57281
282 device_manager_.AddDevice(device_3);
283 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31284 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12285
cco3dca47e22017-05-19 19:23:01286 Initialize();
Donna Wu341df42f2018-11-02 15:18:57287 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12288
Donna Wu341df42f2018-11-02 15:18:57289 device_manager_.RemoveDevice(device_1);
290 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31291 EXPECT_FALSE(display_service_->GetNotification(guid_1));
Donna Wu341df42f2018-11-02 15:18:57292
293 device_manager_.RemoveDevice(device_2);
294 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31295 EXPECT_FALSE(display_service_->GetNotification(guid_2));
Donna Wu341df42f2018-11-02 15:18:57296
297 device_manager_.RemoveDevice(device_3);
298 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31299 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12300}
301
302TEST_F(WebUsbDetectorTest,
303 TwoUsbDevicesWereThereBeforeAndThenRemovedAndNewUsbDeviceAdded) {
juncai1da12032016-07-15 19:10:12304 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57305 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
306 0, 1, "Google", kProductName_1, "002", landing_page_1);
juncai1da12032016-07-15 19:10:12307 std::string guid_1 = device_1->guid();
308
juncai1da12032016-07-15 19:10:12309 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57310 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
311 3, 4, "Google", kProductName_2, "005", landing_page_2);
juncai1da12032016-07-15 19:10:12312 std::string guid_2 = device_2->guid();
313
juncai1da12032016-07-15 19:10:12314 // Two usb devices were added before web_usb_detector was created.
Donna Wu341df42f2018-11-02 15:18:57315 device_manager_.AddDevice(device_1);
316 device_manager_.AddDevice(device_2);
317 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31318 EXPECT_FALSE(display_service_->GetNotification(guid_1));
Evan Stadeea9be28f2018-02-06 18:32:31319 EXPECT_FALSE(display_service_->GetNotification(guid_2));
juncai1da12032016-07-15 19:10:12320
cco3dca47e22017-05-19 19:23:01321 Initialize();
Donna Wu341df42f2018-11-02 15:18:57322 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12323
Donna Wu341df42f2018-11-02 15:18:57324 device_manager_.RemoveDevice(device_1);
325 device_manager_.RemoveDevice(device_2);
326 base::RunLoop().RunUntilIdle();
327
Evan Stadeea9be28f2018-02-06 18:32:31328 EXPECT_FALSE(display_service_->GetNotification(guid_1));
juncai1da12032016-07-15 19:10:12329
Donna Wu341df42f2018-11-02 15:18:57330 device_manager_.AddDevice(device_2);
331 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31332 base::Optional<message_center::Notification> notification =
333 display_service_->GetNotification(guid_2);
334 ASSERT_TRUE(notification);
juncai1da12032016-07-15 19:10:12335 base::string16 expected_title =
336 base::ASCIIToUTF16("Google Product B detected");
337 EXPECT_EQ(expected_title, notification->title());
338 base::string16 expected_message =
Reilly Grant85797cd2017-10-16 18:10:12339 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12340 EXPECT_EQ(expected_message, notification->message());
341 EXPECT_TRUE(notification->delegate() != nullptr);
342
Donna Wu341df42f2018-11-02 15:18:57343 device_manager_.RemoveDevice(device_2);
344 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31345 EXPECT_FALSE(display_service_->GetNotification(guid_2));
juncai1da12032016-07-15 19:10:12346}
347
348TEST_F(WebUsbDetectorTest, ThreeUsbDevicesAddedAndRemoved) {
juncai1da12032016-07-15 19:10:12349 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57350 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
351 0, 1, "Google", kProductName_1, "002", landing_page_1);
juncai1da12032016-07-15 19:10:12352 std::string guid_1 = device_1->guid();
353
juncai1da12032016-07-15 19:10:12354 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57355 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
356 3, 4, "Google", kProductName_2, "005", landing_page_2);
juncai1da12032016-07-15 19:10:12357 std::string guid_2 = device_2->guid();
358
juncai1da12032016-07-15 19:10:12359 GURL landing_page_3(kLandingPage_3);
Donna Wu341df42f2018-11-02 15:18:57360 auto device_3 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
361 6, 7, "Google", kProductName_3, "008", landing_page_3);
juncai1da12032016-07-15 19:10:12362 std::string guid_3 = device_3->guid();
363
cco3dca47e22017-05-19 19:23:01364 Initialize();
Donna Wu341df42f2018-11-02 15:18:57365 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12366
Donna Wu341df42f2018-11-02 15:18:57367 device_manager_.AddDevice(device_1);
368 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31369 base::Optional<message_center::Notification> notification_1 =
370 display_service_->GetNotification(guid_1);
371 ASSERT_TRUE(notification_1);
juncai1da12032016-07-15 19:10:12372 base::string16 expected_title_1 =
373 base::ASCIIToUTF16("Google Product A detected");
374 EXPECT_EQ(expected_title_1, notification_1->title());
375 base::string16 expected_message_1 =
Reilly Grant85797cd2017-10-16 18:10:12376 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12377 EXPECT_EQ(expected_message_1, notification_1->message());
378 EXPECT_TRUE(notification_1->delegate() != nullptr);
379
Donna Wu341df42f2018-11-02 15:18:57380 device_manager_.RemoveDevice(device_1);
381 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31382 EXPECT_FALSE(display_service_->GetNotification(guid_1));
juncai1da12032016-07-15 19:10:12383
Donna Wu341df42f2018-11-02 15:18:57384 device_manager_.AddDevice(device_2);
385 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31386 base::Optional<message_center::Notification> notification_2 =
387 display_service_->GetNotification(guid_2);
388 ASSERT_TRUE(notification_2);
juncai1da12032016-07-15 19:10:12389 base::string16 expected_title_2 =
390 base::ASCIIToUTF16("Google Product B detected");
391 EXPECT_EQ(expected_title_2, notification_2->title());
392 base::string16 expected_message_2 =
Reilly Grant85797cd2017-10-16 18:10:12393 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12394 EXPECT_EQ(expected_message_2, notification_2->message());
395 EXPECT_TRUE(notification_2->delegate() != nullptr);
396
Donna Wu341df42f2018-11-02 15:18:57397 device_manager_.RemoveDevice(device_2);
398 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31399 EXPECT_FALSE(display_service_->GetNotification(guid_2));
juncai1da12032016-07-15 19:10:12400
Donna Wu341df42f2018-11-02 15:18:57401 device_manager_.AddDevice(device_3);
402 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31403 base::Optional<message_center::Notification> notification_3 =
404 display_service_->GetNotification(guid_3);
405 ASSERT_TRUE(notification_3);
juncai1da12032016-07-15 19:10:12406 base::string16 expected_title_3 =
407 base::ASCIIToUTF16("Google Product C detected");
408 EXPECT_EQ(expected_title_3, notification_3->title());
409 base::string16 expected_message_3 =
Reilly Grant85797cd2017-10-16 18:10:12410 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12411 EXPECT_EQ(expected_message_3, notification_3->message());
412 EXPECT_TRUE(notification_3->delegate() != nullptr);
413
Donna Wu341df42f2018-11-02 15:18:57414 device_manager_.RemoveDevice(device_3);
415 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31416 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12417}
418
419TEST_F(WebUsbDetectorTest, ThreeUsbDeviceAddedAndRemovedDifferentOrder) {
juncai1da12032016-07-15 19:10:12420 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57421 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
422 0, 1, "Google", kProductName_1, "002", landing_page_1);
juncai1da12032016-07-15 19:10:12423 std::string guid_1 = device_1->guid();
424
juncai1da12032016-07-15 19:10:12425 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57426 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
427 3, 4, "Google", kProductName_2, "005", landing_page_2);
juncai1da12032016-07-15 19:10:12428 std::string guid_2 = device_2->guid();
429
juncai1da12032016-07-15 19:10:12430 GURL landing_page_3(kLandingPage_3);
Donna Wu341df42f2018-11-02 15:18:57431 auto device_3 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
432 6, 7, "Google", kProductName_3, "008", landing_page_3);
juncai1da12032016-07-15 19:10:12433 std::string guid_3 = device_3->guid();
434
cco3dca47e22017-05-19 19:23:01435 Initialize();
Donna Wu341df42f2018-11-02 15:18:57436 base::RunLoop().RunUntilIdle();
juncai1da12032016-07-15 19:10:12437
Donna Wu341df42f2018-11-02 15:18:57438 device_manager_.AddDevice(device_1);
439 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31440 base::Optional<message_center::Notification> notification_1 =
441 display_service_->GetNotification(guid_1);
442 ASSERT_TRUE(notification_1);
juncai1da12032016-07-15 19:10:12443 base::string16 expected_title_1 =
444 base::ASCIIToUTF16("Google Product A detected");
445 EXPECT_EQ(expected_title_1, notification_1->title());
446 base::string16 expected_message_1 =
Reilly Grant85797cd2017-10-16 18:10:12447 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12448 EXPECT_EQ(expected_message_1, notification_1->message());
449 EXPECT_TRUE(notification_1->delegate() != nullptr);
450
Donna Wu341df42f2018-11-02 15:18:57451 device_manager_.AddDevice(device_2);
452 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31453 base::Optional<message_center::Notification> notification_2 =
454 display_service_->GetNotification(guid_2);
455 ASSERT_TRUE(notification_2);
juncai1da12032016-07-15 19:10:12456 base::string16 expected_title_2 =
457 base::ASCIIToUTF16("Google Product B detected");
458 EXPECT_EQ(expected_title_2, notification_2->title());
459 base::string16 expected_message_2 =
Reilly Grant85797cd2017-10-16 18:10:12460 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12461 EXPECT_EQ(expected_message_2, notification_2->message());
462 EXPECT_TRUE(notification_2->delegate() != nullptr);
463
Donna Wu341df42f2018-11-02 15:18:57464 device_manager_.RemoveDevice(device_2);
465 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31466 EXPECT_FALSE(display_service_->GetNotification(guid_2));
juncai1da12032016-07-15 19:10:12467
Donna Wu341df42f2018-11-02 15:18:57468 device_manager_.AddDevice(device_3);
469 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31470 base::Optional<message_center::Notification> notification_3 =
471 display_service_->GetNotification(guid_3);
472 ASSERT_TRUE(notification_3);
juncai1da12032016-07-15 19:10:12473 base::string16 expected_title_3 =
474 base::ASCIIToUTF16("Google Product C detected");
475 EXPECT_EQ(expected_title_3, notification_3->title());
476 base::string16 expected_message_3 =
Reilly Grant85797cd2017-10-16 18:10:12477 base::ASCIIToUTF16("Go to www.google.com to connect.");
juncai1da12032016-07-15 19:10:12478 EXPECT_EQ(expected_message_3, notification_3->message());
479 EXPECT_TRUE(notification_3->delegate() != nullptr);
480
Donna Wu341df42f2018-11-02 15:18:57481 device_manager_.RemoveDevice(device_1);
482 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31483 EXPECT_FALSE(display_service_->GetNotification(guid_1));
juncai1da12032016-07-15 19:10:12484
Donna Wu341df42f2018-11-02 15:18:57485 device_manager_.RemoveDevice(device_3);
486 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31487 EXPECT_FALSE(display_service_->GetNotification(guid_3));
juncai1da12032016-07-15 19:10:12488}
cco3dca47e22017-05-19 19:23:01489
490TEST_F(WebUsbDetectorTest, UsbDeviceAddedWhileActiveTabUrlIsLandingPage) {
491 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57492 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
493 0, 1, "Google", kProductName_1, "002", landing_page_1);
cco3dca47e22017-05-19 19:23:01494 std::string guid_1 = device_1->guid();
495
496 Initialize();
Donna Wu341df42f2018-11-02 15:18:57497 base::RunLoop().RunUntilIdle();
cco3dca47e22017-05-19 19:23:01498
499 AddTab(browser(), landing_page_1);
500
Donna Wu341df42f2018-11-02 15:18:57501 device_manager_.AddDevice(device_1);
502 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31503 EXPECT_FALSE(display_service_->GetNotification(guid_1));
cco3dca47e22017-05-19 19:23:01504}
505
506TEST_F(WebUsbDetectorTest, UsbDeviceAddedBeforeActiveTabUrlIsLandingPage) {
507 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57508 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
509 0, 1, "Google", kProductName_1, "002", landing_page_1);
cco3dca47e22017-05-19 19:23:01510 std::string guid_1 = device_1->guid();
511
512 base::HistogramTester histogram_tester;
513 Initialize();
Donna Wu341df42f2018-11-02 15:18:57514 base::RunLoop().RunUntilIdle();
cco3dca47e22017-05-19 19:23:01515
Donna Wu341df42f2018-11-02 15:18:57516 device_manager_.AddDevice(device_1);
517 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31518 EXPECT_TRUE(display_service_->GetNotification(guid_1));
cco3dca47e22017-05-19 19:23:01519
520 AddTab(browser(), landing_page_1);
Evan Stadeea9be28f2018-02-06 18:32:31521 EXPECT_FALSE(display_service_->GetNotification(guid_1));
cco3dca47e22017-05-19 19:23:01522 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 3, 1);
523}
524
525TEST_F(WebUsbDetectorTest,
526 NotificationClickedWhileInactiveTabUrlIsLandingPage) {
527 GURL landing_page_1(kLandingPage_1);
528 GURL landing_page_2(kLandingPage_2);
Donna Wu341df42f2018-11-02 15:18:57529 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
530 0, 1, "Google", kProductName_1, "002", landing_page_1);
cco3dca47e22017-05-19 19:23:01531 std::string guid_1 = device_1->guid();
532 TabStripModel* tab_strip_model = browser()->tab_strip_model();
533
534 base::HistogramTester histogram_tester;
535 Initialize();
Donna Wu341df42f2018-11-02 15:18:57536 base::RunLoop().RunUntilIdle();
cco3dca47e22017-05-19 19:23:01537
538 AddTab(browser(), landing_page_1);
539 AddTab(browser(), landing_page_2);
540
Donna Wu341df42f2018-11-02 15:18:57541 device_manager_.AddDevice(device_1);
542 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31543 base::Optional<message_center::Notification> notification_1 =
544 display_service_->GetNotification(guid_1);
545 ASSERT_TRUE(notification_1);
cco3dca47e22017-05-19 19:23:01546 EXPECT_EQ(2, tab_strip_model->count());
547
Evan Stadee0921092018-04-04 21:13:09548 notification_1->delegate()->Click(base::nullopt, base::nullopt);
cco3dca47e22017-05-19 19:23:01549 EXPECT_EQ(2, tab_strip_model->count());
550 content::WebContents* web_contents =
551 tab_strip_model->GetWebContentsAt(tab_strip_model->active_index());
552 EXPECT_EQ(landing_page_1, web_contents->GetURL());
Evan Stadeea9be28f2018-02-06 18:32:31553 EXPECT_FALSE(display_service_->GetNotification(guid_1));
cco3dca47e22017-05-19 19:23:01554 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 2, 1);
555}
556
557TEST_F(WebUsbDetectorTest, NotificationClickedWhileNoTabUrlIsLandingPage) {
558 GURL landing_page_1(kLandingPage_1);
Donna Wu341df42f2018-11-02 15:18:57559 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
560 0, 1, "Google", kProductName_1, "002", landing_page_1);
cco3dca47e22017-05-19 19:23:01561 std::string guid_1 = device_1->guid();
562 TabStripModel* tab_strip_model = browser()->tab_strip_model();
563
564 base::HistogramTester histogram_tester;
565 Initialize();
Donna Wu341df42f2018-11-02 15:18:57566 base::RunLoop().RunUntilIdle();
cco3dca47e22017-05-19 19:23:01567
Donna Wu341df42f2018-11-02 15:18:57568 device_manager_.AddDevice(device_1);
569 base::RunLoop().RunUntilIdle();
Evan Stadeea9be28f2018-02-06 18:32:31570 base::Optional<message_center::Notification> notification_1 =
571 display_service_->GetNotification(guid_1);
572 ASSERT_TRUE(notification_1);
cco3dca47e22017-05-19 19:23:01573 EXPECT_EQ(0, tab_strip_model->count());
574
Evan Stadee0921092018-04-04 21:13:09575 notification_1->delegate()->Click(base::nullopt, base::nullopt);
cco3dca47e22017-05-19 19:23:01576 EXPECT_EQ(1, tab_strip_model->count());
577 content::WebContents* web_contents =
578 tab_strip_model->GetWebContentsAt(tab_strip_model->active_index());
579 EXPECT_EQ(landing_page_1, web_contents->GetURL());
Evan Stadeea9be28f2018-02-06 18:32:31580 EXPECT_FALSE(display_service_->GetNotification(guid_1));
cco3dca47e22017-05-19 19:23:01581 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 2, 1);
582}
James Hollyerc59c9c42018-12-20 03:39:06583
584TEST_F(WebUsbDetectorTest, UsbDeviceAddedBeforeActiveTabFuzzyUrlIsLandingPage) {
585 GURL landing_page_1(kLandingPage_1);
586 GURL landing_page_1_fuzzed(kLandingPage_1_fuzzed);
587 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
588 0, 1, "Google", kProductName_1, "002", landing_page_1);
589 std::string guid_1 = device_1->guid();
590
591 base::HistogramTester histogram_tester;
592 Initialize();
593 base::RunLoop().RunUntilIdle();
594
595 device_manager_.AddDevice(device_1);
596 base::RunLoop().RunUntilIdle();
597 EXPECT_TRUE(display_service_->GetNotification(guid_1));
598
599 AddTab(browser(), landing_page_1_fuzzed);
600 EXPECT_FALSE(display_service_->GetNotification(guid_1));
601 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 3, 1);
602}
603
604TEST_F(WebUsbDetectorTest, UsbDeviceAddedWhileActiveTabFuzzyUrlIsLandingPage) {
605 GURL landing_page_1(kLandingPage_1);
606 GURL landing_page_1_fuzzed(kLandingPage_1_fuzzed);
607 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
608 0, 1, "Google", kProductName_3, "002", landing_page_1);
609 std::string guid_1 = device_1->guid();
610
611 Initialize();
612 base::RunLoop().RunUntilIdle();
613
614 AddTab(browser(), landing_page_1_fuzzed);
615
616 device_manager_.AddDevice(device_1);
617 base::RunLoop().RunUntilIdle();
618 EXPECT_FALSE(display_service_->GetNotification(guid_1));
619}
620
James Hollyerd7cf3102019-01-03 00:07:24621TEST_F(WebUsbDetectorTest, TwoDevicesSameLandingPageAddedRemovedAndAddedAgain) {
622 GURL landing_page_1(kLandingPage_1);
623 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
624 0, 1, "Google", kProductName_1, "002", landing_page_1);
625 std::string guid_1 = device_1->guid();
626
627 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
628 3, 4, "Google", kProductName_2, "005", landing_page_1);
629 std::string guid_2 = device_2->guid();
630
631 Initialize();
632 base::RunLoop().RunUntilIdle();
633
634 device_manager_.AddDevice(device_1);
635 base::RunLoop().RunUntilIdle();
636 base::Optional<message_center::Notification> notification_1 =
637 display_service_->GetNotification(guid_1);
638 ASSERT_TRUE(notification_1);
639 base::string16 expected_title_1 =
640 base::ASCIIToUTF16("Google Product A detected");
641 EXPECT_EQ(expected_title_1, notification_1->title());
642 base::string16 expected_message_1 =
643 base::ASCIIToUTF16("Go to www.google.com to connect.");
644 EXPECT_EQ(expected_message_1, notification_1->message());
645 EXPECT_TRUE(notification_1->delegate() != nullptr);
646
647 device_manager_.AddDevice(device_2);
648 base::RunLoop().RunUntilIdle();
649 ASSERT_FALSE(display_service_->GetNotification(guid_2));
650
651 device_manager_.RemoveDevice(device_2);
652 base::RunLoop().RunUntilIdle();
653 EXPECT_TRUE(display_service_->GetNotification(guid_1));
654
655 device_manager_.RemoveDevice(device_1);
656 base::RunLoop().RunUntilIdle();
657 EXPECT_FALSE(display_service_->GetNotification(guid_1));
658
659 device_manager_.AddDevice(device_2);
660 base::RunLoop().RunUntilIdle();
661 base::Optional<message_center::Notification> notification_2 =
662 display_service_->GetNotification(guid_2);
663 ASSERT_TRUE(notification_2);
664 base::string16 expected_title_2 =
665 base::ASCIIToUTF16("Google Product B detected");
666 EXPECT_EQ(expected_title_2, notification_2->title());
667 base::string16 expected_message_2 =
668 base::ASCIIToUTF16("Go to www.google.com to connect.");
669 EXPECT_EQ(expected_message_2, notification_2->message());
670 EXPECT_TRUE(notification_2->delegate() != nullptr);
671
672 device_manager_.AddDevice(device_1);
673 base::RunLoop().RunUntilIdle();
674 ASSERT_FALSE(display_service_->GetNotification(guid_1));
675}
676
677TEST_F(
678 WebUsbDetectorTest,
679 DeviceWithSameLandingPageAddedAfterNotificationClickedAndThenNewTabActive) {
680 GURL landing_page_1(kLandingPage_1);
681 GURL landing_page_2(kLandingPage_2);
682 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
683 0, 1, "Google", kProductName_1, "002", landing_page_1);
684 std::string guid_1 = device_1->guid();
685
686 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
687 0, 1, "Google", kProductName_2, "002", landing_page_1);
688 std::string guid_2 = device_2->guid();
689
690 TabStripModel* tab_strip_model = browser()->tab_strip_model();
691
692 base::HistogramTester histogram_tester;
693 Initialize();
694 base::RunLoop().RunUntilIdle();
695
696 device_manager_.AddDevice(device_1);
697 base::RunLoop().RunUntilIdle();
698 base::Optional<message_center::Notification> notification_1 =
699 display_service_->GetNotification(guid_1);
700 ASSERT_TRUE(notification_1);
701 EXPECT_EQ(0, tab_strip_model->count());
702
703 notification_1->delegate()->Click(base::nullopt, base::nullopt);
704 EXPECT_EQ(1, tab_strip_model->count());
705 content::WebContents* web_contents =
706 tab_strip_model->GetWebContentsAt(tab_strip_model->active_index());
707 EXPECT_EQ(landing_page_1, web_contents->GetURL());
708 EXPECT_FALSE(display_service_->GetNotification(guid_1));
709 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 2, 1);
710
711 AddTab(browser(), landing_page_2);
712
713 device_manager_.AddDevice(device_2);
714 base::RunLoop().RunUntilIdle();
715 ASSERT_TRUE(display_service_->GetNotification(guid_2));
716}
717
James Hollyerc59c9c42018-12-20 03:39:06718TEST_F(WebUsbDetectorTest,
719 NotificationClickedWhileInactiveTabFuzzyUrlIsLandingPage) {
720 GURL landing_page_1(kLandingPage_1);
721 GURL landing_page_1_fuzzed(kLandingPage_1_fuzzed);
722 GURL landing_page_2(kLandingPage_2);
723 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
724 0, 1, "Google", kProductName_1, "002", landing_page_1);
725 std::string guid_1 = device_1->guid();
726 TabStripModel* tab_strip_model = browser()->tab_strip_model();
727
728 base::HistogramTester histogram_tester;
729 Initialize();
730 base::RunLoop().RunUntilIdle();
731
732 AddTab(browser(), landing_page_1_fuzzed);
733 AddTab(browser(), landing_page_2);
734
735 device_manager_.AddDevice(device_1);
736 base::RunLoop().RunUntilIdle();
737 base::Optional<message_center::Notification> notification_1 =
738 display_service_->GetNotification(guid_1);
739 ASSERT_TRUE(notification_1);
740 EXPECT_EQ(2, tab_strip_model->count());
741
742 notification_1->delegate()->Click(base::nullopt, base::nullopt);
743 EXPECT_EQ(2, tab_strip_model->count());
744 content::WebContents* web_contents =
745 tab_strip_model->GetWebContentsAt(tab_strip_model->active_index());
746 EXPECT_EQ(landing_page_1_fuzzed, web_contents->GetURL());
747 EXPECT_FALSE(display_service_->GetNotification(guid_1));
748 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 2, 1);
749}
750
James Hollyerd7cf3102019-01-03 00:07:24751TEST_F(WebUsbDetectorTest,
752 DeviceWithSameLandingPageAddedAfterPageVisitedAndNewTabActive) {
753 GURL landing_page_1(kLandingPage_1);
754 GURL landing_page_2(kLandingPage_2);
755 auto device_1 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
756 0, 1, "Google", kProductName_1, "002", landing_page_1);
757 std::string guid_1 = device_1->guid();
758
759 auto device_2 = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
760 0, 1, "Google", kProductName_1, "002", landing_page_1);
761 std::string guid_2 = device_2->guid();
762
763 base::HistogramTester histogram_tester;
764 Initialize();
765 base::RunLoop().RunUntilIdle();
766
767 device_manager_.AddDevice(device_1);
768 base::RunLoop().RunUntilIdle();
769 EXPECT_TRUE(display_service_->GetNotification(guid_1));
770
771 AddTab(browser(), landing_page_1);
772 EXPECT_FALSE(display_service_->GetNotification(guid_1));
773 histogram_tester.ExpectUniqueSample("WebUsb.NotificationClosed", 3, 1);
774
775 AddTab(browser(), landing_page_2);
776 device_manager_.AddDevice(device_2);
777 base::RunLoop().RunUntilIdle();
778 EXPECT_TRUE(display_service_->GetNotification(guid_2));
779}
780
reillygdfd32df2016-10-18 02:42:16781#endif // !OS_WIN