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

Side by Side Diff: chrome/browser/chromeos/note_taking_helper_unittest.cc

Issue 2587913006: chromeos: Notify about Chrome note-taking apps. (Closed)
Patch Set: work around profile lifecycle wonkiness in browser tests Created 4 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
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 #include "chrome/browser/chromeos/note_taking_helper.h" 5 #include "chrome/browser/chromeos/note_taking_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/file_manager/path_util.h" 17 #include "chrome/browser/chromeos/file_manager/path_util.h"
17 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/test_extension_system.h" 19 #include "chrome/browser/extensions/test_extension_system.h"
19 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" 20 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/browser_with_test_window_test.h" 22 #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"
22 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/fake_session_manager_client.h" 26 #include "chromeos/dbus/fake_session_manager_client.h"
24 #include "components/arc/arc_bridge_service.h" 27 #include "components/arc/arc_bridge_service.h"
25 #include "components/arc/arc_service_manager.h" 28 #include "components/arc/arc_service_manager.h"
26 #include "components/arc/common/intent_helper.mojom.h" 29 #include "components/arc/common/intent_helper.mojom.h"
27 #include "components/arc/test/fake_intent_helper_instance.h" 30 #include "components/arc/test/fake_intent_helper_instance.h"
31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h"
28 #include "extensions/common/api/app_runtime.h" 33 #include "extensions/common/api/app_runtime.h"
29 #include "extensions/common/extension_builder.h" 34 #include "extensions/common/extension_builder.h"
30 #include "extensions/common/extension_id.h" 35 #include "extensions/common/extension_id.h"
31 #include "extensions/common/value_builder.h" 36 #include "extensions/common/value_builder.h"
32 #include "url/gurl.h" 37 #include "url/gurl.h"
33 38
34 namespace app_runtime = extensions::api::app_runtime; 39 namespace app_runtime = extensions::api::app_runtime;
35 40
36 using arc::mojom::IntentHandlerInfo; 41 using arc::mojom::IntentHandlerInfo;
37 using arc::mojom::IntentHandlerInfoPtr; 42 using arc::mojom::IntentHandlerInfoPtr;
38 using HandledIntent = arc::FakeIntentHelperInstance::HandledIntent; 43 using HandledIntent = arc::FakeIntentHelperInstance::HandledIntent;
39 44
40 namespace chromeos { 45 namespace chromeos {
41 namespace { 46 namespace {
42 47
48 // Name of default profile.
49 const char kTestProfileName[] = "test-profile";
50
43 // Helper functions returning strings that can be used to compare information 51 // Helper functions returning strings that can be used to compare information
44 // about available note-taking apps. 52 // about available note-taking apps.
45 std::string GetAppString(const std::string& id, 53 std::string GetAppString(const std::string& id,
46 const std::string& name, 54 const std::string& name,
47 bool preferred) { 55 bool preferred) {
48 return base::StringPrintf("%s %s %d", id.c_str(), name.c_str(), preferred); 56 return base::StringPrintf("%s %s %d", id.c_str(), name.c_str(), preferred);
49 } 57 }
50 std::string GetAppString(const NoteTakingAppInfo& info) { 58 std::string GetAppString(const NoteTakingAppInfo& info) {
51 return GetAppString(info.app_id, info.name, info.preferred); 59 return GetAppString(info.app_id, info.name, info.preferred);
52 } 60 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void SetUp() override { 118 void SetUp() override {
111 // This is needed to avoid log spam due to ArcSessionManager's 119 // This is needed to avoid log spam due to ArcSessionManager's
112 // RemoveArcData() calls failing. 120 // RemoveArcData() calls failing.
113 if (DBusThreadManager::IsInitialized()) 121 if (DBusThreadManager::IsInitialized())
114 DBusThreadManager::Shutdown(); 122 DBusThreadManager::Shutdown();
115 session_manager_client_ = new FakeSessionManagerClient(); 123 session_manager_client_ = new FakeSessionManagerClient();
116 session_manager_client_->set_arc_available(true); 124 session_manager_client_->set_arc_available(true);
117 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 125 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
118 std::unique_ptr<SessionManagerClient>(session_manager_client_)); 126 std::unique_ptr<SessionManagerClient>(session_manager_client_));
119 127
128 profile_manager_.reset(
129 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
130 ASSERT_TRUE(profile_manager_->SetUp());
120 BrowserWithTestWindowTest::SetUp(); 131 BrowserWithTestWindowTest::SetUp();
121 132 InitExtensionService(profile());
122 extensions::TestExtensionSystem* extension_system =
123 static_cast<extensions::TestExtensionSystem*>(
124 extensions::ExtensionSystem::Get(profile()));
125 extension_system->CreateExtensionService(
126 base::CommandLine::ForCurrentProcess(),
127 base::FilePath() /* install_directory */,
128 false /* autoupdate_enabled */);
129 } 133 }
130 134
131 void TearDown() override { 135 void TearDown() override {
132 if (initialized_) { 136 if (initialized_) {
133 NoteTakingHelper::Shutdown(); 137 NoteTakingHelper::Shutdown();
134 arc_test_.TearDown(); 138 arc_test_.TearDown();
135 } 139 }
136 extensions::ExtensionSystem::Get(profile())->Shutdown(); 140 extensions::ExtensionSystem::Get(profile())->Shutdown();
137 BrowserWithTestWindowTest::TearDown(); 141 BrowserWithTestWindowTest::TearDown();
138 DBusThreadManager::Shutdown(); 142 DBusThreadManager::Shutdown();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 .Build()) 200 .Build())
197 .Build()) 201 .Build())
198 .Build()) 202 .Build())
199 .Build(); 203 .Build();
200 return extensions::ExtensionBuilder() 204 return extensions::ExtensionBuilder()
201 .SetManifest(std::move(manifest)) 205 .SetManifest(std::move(manifest))
202 .SetID(id) 206 .SetID(id)
203 .Build(); 207 .Build();
204 } 208 }
205 209
206 // Installs or uninstalls the passed-in extension. 210 // Initializes extensions-related objects for |profile|. Tests only need to
207 void InstallExtension(const extensions::Extension* extension) { 211 // call this if they create additional profiles of their own.
208 extensions::ExtensionSystem::Get(profile()) 212 void InitExtensionService(Profile* profile) {
213 extensions::TestExtensionSystem* extension_system =
214 static_cast<extensions::TestExtensionSystem*>(
215 extensions::ExtensionSystem::Get(profile));
216 extension_system->CreateExtensionService(
217 base::CommandLine::ForCurrentProcess(),
218 base::FilePath() /* install_directory */,
219 false /* autoupdate_enabled */);
220 }
221
222 // Installs or uninstalls |extension| in |profile|.
223 void InstallExtension(const extensions::Extension* extension,
224 Profile* profile) {
225 extensions::ExtensionSystem::Get(profile)
209 ->extension_service() 226 ->extension_service()
210 ->AddExtension(extension); 227 ->AddExtension(extension);
211 } 228 }
212 void UninstallExtension(const extensions::Extension* extension) { 229 void UninstallExtension(const extensions::Extension* extension,
213 extensions::ExtensionSystem::Get(profile()) 230 Profile* profile) {
231 extensions::ExtensionSystem::Get(profile)
214 ->extension_service() 232 ->extension_service()
215 ->UnloadExtension(extension->id(), 233 ->UnloadExtension(extension->id(),
216 extensions::UnloadedExtensionInfo::REASON_UNINSTALL); 234 extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
217 } 235 }
218 236
237 // BrowserWithTestWindowTest:
238 TestingProfile* CreateProfile() override {
239 // Ensure that the profile created by BrowserWithTestWindowTest is
240 // registered with |profile_manager_|.
241 return profile_manager_->CreateTestingProfile(kTestProfileName);
242 }
243 void DestroyProfile(TestingProfile* profile) override {
244 return profile_manager_->DeleteTestingProfile(kTestProfileName);
245 }
246
219 // Info about launched Chrome apps, in the order they were launched. 247 // Info about launched Chrome apps, in the order they were launched.
220 std::vector<ChromeAppLaunchInfo> launched_chrome_apps_; 248 std::vector<ChromeAppLaunchInfo> launched_chrome_apps_;
221 249
222 arc::FakeIntentHelperInstance intent_helper_; 250 arc::FakeIntentHelperInstance intent_helper_;
251 std::unique_ptr<TestingProfileManager> profile_manager_;
223 252
224 private: 253 private:
225 // Callback registered with the helper to record Chrome app launch requests. 254 // Callback registered with the helper to record Chrome app launch requests.
226 void LaunchChromeApp(Profile* passed_profile, 255 void LaunchChromeApp(Profile* passed_profile,
227 const extensions::Extension* extension, 256 const extensions::Extension* extension,
228 std::unique_ptr<app_runtime::ActionData> action_data, 257 std::unique_ptr<app_runtime::ActionData> action_data,
229 const base::FilePath& path) { 258 const base::FilePath& path) {
230 EXPECT_EQ(profile(), passed_profile); 259 EXPECT_EQ(profile(), passed_profile);
231 EXPECT_EQ(app_runtime::ActionType::ACTION_TYPE_NEW_NOTE, 260 EXPECT_EQ(app_runtime::ActionType::ACTION_TYPE_NEW_NOTE,
232 action_data->action_type); 261 action_data->action_type);
233 launched_chrome_apps_.push_back(ChromeAppLaunchInfo{extension->id(), path}); 262 launched_chrome_apps_.push_back(ChromeAppLaunchInfo{extension->id(), path});
234 } 263 }
235 264
236 // Has Init() been called? 265 // Has Init() been called?
237 bool initialized_ = false; 266 bool initialized_ = false;
238 267
239 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned. 268 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned.
240
241 ArcAppTest arc_test_; 269 ArcAppTest arc_test_;
242 270
243 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest); 271 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest);
244 }; 272 };
245 273
246 TEST_F(NoteTakingHelperTest, PaletteNotEnabled) { 274 TEST_F(NoteTakingHelperTest, PaletteNotEnabled) {
247 // Without the palette enabled, IsAppAvailable() should return false. 275 // Without the palette enabled, IsAppAvailable() should return false.
248 Init(0); 276 Init(0);
249 auto extension = 277 auto extension =
250 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); 278 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
251 InstallExtension(extension.get()); 279 InstallExtension(extension.get(), profile());
252 EXPECT_FALSE(helper()->IsAppAvailable(profile())); 280 EXPECT_FALSE(helper()->IsAppAvailable(profile()));
253 } 281 }
254 282
255 TEST_F(NoteTakingHelperTest, ListChromeApps) { 283 TEST_F(NoteTakingHelperTest, ListChromeApps) {
256 Init(ENABLE_PALETTE); 284 Init(ENABLE_PALETTE);
257 285
258 // Start out without any note-taking apps installed. 286 // Start out without any note-taking apps installed.
259 EXPECT_FALSE(helper()->IsAppAvailable(profile())); 287 EXPECT_FALSE(helper()->IsAppAvailable(profile()));
260 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); 288 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty());
261 289
262 // If only the prod version of the app is installed, it should be returned. 290 // If only the prod version of the app is installed, it should be returned.
263 const std::string kProdName = "Google Keep [prod]"; 291 const std::string kProdName = "Google Keep [prod]";
264 auto prod_extension = 292 auto prod_extension =
265 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName); 293 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName);
266 InstallExtension(prod_extension.get()); 294 InstallExtension(prod_extension.get(), profile());
267 EXPECT_TRUE(helper()->IsAppAvailable(profile())); 295 EXPECT_TRUE(helper()->IsAppAvailable(profile()));
268 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); 296 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile());
269 ASSERT_EQ(1u, apps.size()); 297 ASSERT_EQ(1u, apps.size());
270 EXPECT_EQ( 298 EXPECT_EQ(
271 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 299 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
272 GetAppString(apps[0])); 300 GetAppString(apps[0]));
273 301
274 // If the dev version is also installed, it should be listed before the prod 302 // If the dev version is also installed, it should be listed before the prod
275 // version. 303 // version.
276 const std::string kDevName = "Google Keep [dev]"; 304 const std::string kDevName = "Google Keep [dev]";
277 auto dev_extension = 305 auto dev_extension =
278 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, kDevName); 306 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, kDevName);
279 InstallExtension(dev_extension.get()); 307 InstallExtension(dev_extension.get(), profile());
280 apps = helper()->GetAvailableApps(profile()); 308 apps = helper()->GetAvailableApps(profile());
281 ASSERT_EQ(2u, apps.size()); 309 ASSERT_EQ(2u, apps.size());
282 EXPECT_EQ( 310 EXPECT_EQ(
283 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 311 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
284 GetAppString(apps[0])); 312 GetAppString(apps[0]));
285 EXPECT_EQ( 313 EXPECT_EQ(
286 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 314 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
287 GetAppString(apps[1])); 315 GetAppString(apps[1]));
288 316
289 // Now install a random extension and check that it's ignored. 317 // Now install a random extension and check that it's ignored.
290 const extensions::ExtensionId kOtherId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 318 const extensions::ExtensionId kOtherId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
291 const std::string kOtherName = "Some Other App"; 319 const std::string kOtherName = "Some Other App";
292 auto other_extension = CreateExtension(kOtherId, kOtherName); 320 auto other_extension = CreateExtension(kOtherId, kOtherName);
293 InstallExtension(other_extension.get()); 321 InstallExtension(other_extension.get(), profile());
294 apps = helper()->GetAvailableApps(profile()); 322 apps = helper()->GetAvailableApps(profile());
295 ASSERT_EQ(2u, apps.size()); 323 ASSERT_EQ(2u, apps.size());
296 EXPECT_EQ( 324 EXPECT_EQ(
297 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 325 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
298 GetAppString(apps[0])); 326 GetAppString(apps[0]));
299 EXPECT_EQ( 327 EXPECT_EQ(
300 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 328 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
301 GetAppString(apps[1])); 329 GetAppString(apps[1]));
302 330
303 // Mark the prod version as preferred. 331 // Mark the prod version as preferred.
304 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId); 332 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId);
305 apps = helper()->GetAvailableApps(profile()); 333 apps = helper()->GetAvailableApps(profile());
306 ASSERT_EQ(2u, apps.size()); 334 ASSERT_EQ(2u, apps.size());
307 EXPECT_EQ( 335 EXPECT_EQ(
308 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 336 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
309 GetAppString(apps[0])); 337 GetAppString(apps[0]));
310 EXPECT_EQ( 338 EXPECT_EQ(
311 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), 339 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true),
312 GetAppString(apps[1])); 340 GetAppString(apps[1]));
313 } 341 }
314 342
315 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { 343 TEST_F(NoteTakingHelperTest, LaunchChromeApp) {
316 Init(ENABLE_PALETTE); 344 Init(ENABLE_PALETTE);
317 auto extension = 345 auto extension =
318 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); 346 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
319 InstallExtension(extension.get()); 347 InstallExtension(extension.get(), profile());
320 348
321 // Check the Chrome app is launched with the correct parameters. 349 // Check the Chrome app is launched with the correct parameters.
322 const base::FilePath kPath("/foo/bar/photo.jpg"); 350 const base::FilePath kPath("/foo/bar/photo.jpg");
323 helper()->LaunchAppForNewNote(profile(), kPath); 351 helper()->LaunchAppForNewNote(profile(), kPath);
324 ASSERT_EQ(1u, launched_chrome_apps_.size()); 352 ASSERT_EQ(1u, launched_chrome_apps_.size());
325 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId, 353 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId,
326 launched_chrome_apps_[0].id); 354 launched_chrome_apps_[0].id);
327 EXPECT_EQ(kPath, launched_chrome_apps_[0].path); 355 EXPECT_EQ(kPath, launched_chrome_apps_[0].path);
328 } 356 }
329 357
330 TEST_F(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) { 358 TEST_F(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) {
331 Init(ENABLE_PALETTE); 359 Init(ENABLE_PALETTE);
332 auto prod_extension = 360 auto prod_extension =
333 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod"); 361 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod");
334 InstallExtension(prod_extension.get()); 362 InstallExtension(prod_extension.get(), profile());
335 auto dev_extension = 363 auto dev_extension =
336 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev"); 364 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev");
337 InstallExtension(dev_extension.get()); 365 InstallExtension(dev_extension.get(), profile());
338 366
339 // Set the prod app as the default and check that it's launched. 367 // Set the prod app as the default and check that it's launched.
340 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId); 368 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId);
341 helper()->LaunchAppForNewNote(profile(), base::FilePath()); 369 helper()->LaunchAppForNewNote(profile(), base::FilePath());
342 ASSERT_EQ(1u, launched_chrome_apps_.size()); 370 ASSERT_EQ(1u, launched_chrome_apps_.size());
343 ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId, 371 ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId,
344 launched_chrome_apps_[0].id); 372 launched_chrome_apps_[0].id);
345 373
346 // Now uninstall the prod app and check that we fall back to the dev app. 374 // Now uninstall the prod app and check that we fall back to the dev app.
347 UninstallExtension(prod_extension.get()); 375 UninstallExtension(prod_extension.get(), profile());
348 launched_chrome_apps_.clear(); 376 launched_chrome_apps_.clear();
349 helper()->LaunchAppForNewNote(profile(), base::FilePath()); 377 helper()->LaunchAppForNewNote(profile(), base::FilePath());
350 ASSERT_EQ(1u, launched_chrome_apps_.size()); 378 ASSERT_EQ(1u, launched_chrome_apps_.size());
351 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id); 379 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id);
352 } 380 }
353 381
354 TEST_F(NoteTakingHelperTest, ArcInitiallyDisabled) { 382 TEST_F(NoteTakingHelperTest, ArcInitiallyDisabled) {
355 Init(ENABLE_PALETTE); 383 Init(ENABLE_PALETTE);
356 EXPECT_FALSE(helper()->android_enabled()); 384 EXPECT_FALSE(helper()->android_enabled());
357 EXPECT_FALSE(helper()->android_apps_received()); 385 EXPECT_FALSE(helper()->android_apps_received());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kRemovablePath)), 497 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kRemovablePath)),
470 GetIntentString(intent_helper_.handled_intents()[0])); 498 GetIntentString(intent_helper_.handled_intents()[0]));
471 499
472 // When a path that isn't accessible to ARC is passed, the request should be 500 // When a path that isn't accessible to ARC is passed, the request should be
473 // dropped. 501 // dropped.
474 intent_helper_.clear_handled_intents(); 502 intent_helper_.clear_handled_intents();
475 helper()->LaunchAppForNewNote(profile(), base::FilePath("/bad/path.jpg")); 503 helper()->LaunchAppForNewNote(profile(), base::FilePath("/bad/path.jpg"));
476 EXPECT_TRUE(intent_helper_.handled_intents().empty()); 504 EXPECT_TRUE(intent_helper_.handled_intents().empty());
477 } 505 }
478 506
479 TEST_F(NoteTakingHelperTest, NotifyObserver) { 507 TEST_F(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) {
480 Init(ENABLE_PALETTE | ENABLE_ARC); 508 Init(ENABLE_PALETTE | ENABLE_ARC);
481 TestObserver observer; 509 TestObserver observer;
482 510
483 // Let the app-fetching callback run and check that the observer is notified. 511 // Let the app-fetching callback run and check that the observer is notified.
484 base::RunLoop().RunUntilIdle(); 512 base::RunLoop().RunUntilIdle();
485 EXPECT_EQ(1, observer.num_updates()); 513 EXPECT_EQ(1, observer.num_updates());
486 514
487 // Disabling and enabling ARC should also notify the observer (and enabling 515 // Disabling and enabling ARC should also notify the observer (and enabling
488 // should request apps again). 516 // should request apps again).
489 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 517 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
490 EXPECT_EQ(2, observer.num_updates()); 518 EXPECT_EQ(2, observer.num_updates());
491 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 519 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
492 EXPECT_EQ(3, observer.num_updates()); 520 EXPECT_EQ(3, observer.num_updates());
493 base::RunLoop().RunUntilIdle(); 521 base::RunLoop().RunUntilIdle();
494 EXPECT_EQ(4, observer.num_updates()); 522 EXPECT_EQ(4, observer.num_updates());
495 523
496 // Update intent filters and check that the observer is notified again after 524 // Update intent filters and check that the observer is notified again after
497 // apps are received. 525 // apps are received.
498 helper()->OnIntentFiltersUpdated(); 526 helper()->OnIntentFiltersUpdated();
499 EXPECT_EQ(4, observer.num_updates()); 527 EXPECT_EQ(4, observer.num_updates());
500 base::RunLoop().RunUntilIdle(); 528 base::RunLoop().RunUntilIdle();
501 EXPECT_EQ(5, observer.num_updates()); 529 EXPECT_EQ(5, observer.num_updates());
502 } 530 }
503 531
532 TEST_F(NoteTakingHelperTest, NotifyObserverAboutChromeApps) {
533 Init(ENABLE_PALETTE);
534 TestObserver observer;
535 ASSERT_EQ(0, observer.num_updates());
536
537 // Notify that the prod Keep app was installed for the initial profile. Chrome
538 // extensions are queried dynamically when GetAvailableApps() is called, so we
539 // don't need to actually install it.
540 auto keep_extension =
541 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
542 InstallExtension(keep_extension.get(), profile());
543 EXPECT_EQ(1, observer.num_updates());
544
545 // Unloading the extension should also trigger a notification.
546 UninstallExtension(keep_extension.get(), profile());
547 EXPECT_EQ(2, observer.num_updates());
548
549 // Non-whitelisted apps shouldn't trigger notifications.
550 auto other_extension =
551 CreateExtension("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Some Other App");
552 InstallExtension(other_extension.get(), profile());
553 EXPECT_EQ(2, observer.num_updates());
554 UninstallExtension(other_extension.get(), profile());
555 EXPECT_EQ(2, observer.num_updates());
556
557 // Add a second profile and check that it triggers notifications too.
558 const std::string kSecondProfileName = "second-profile";
559 TestingProfile* second_profile =
560 profile_manager_->CreateTestingProfile(kSecondProfileName);
561 InitExtensionService(second_profile);
562 ASSERT_EQ(2, observer.num_updates());
563 InstallExtension(keep_extension.get(), second_profile);
564 EXPECT_EQ(3, observer.num_updates());
565 UninstallExtension(keep_extension.get(), second_profile);
566 EXPECT_EQ(4, observer.num_updates());
567 profile_manager_->DeleteTestingProfile(kSecondProfileName);
568 }
569
504 } // namespace chromeos 570 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698