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

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

Issue 2587913006: chromeos: Notify about Chrome note-taking apps. (Closed)
Patch Set: drop NOTIFICATION_PROFILE_DESTROYED and instead stop observing registries on destruction 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
« no previous file with comments | « chrome/browser/chromeos/note_taking_helper.cc ('k') | 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 #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 29 matching lines...) Expand all
82 return url.spec(); 90 return url.spec();
83 } 91 }
84 92
85 // Implementation of NoteTakingHelper::Observer for testing. 93 // Implementation of NoteTakingHelper::Observer for testing.
86 class TestObserver : public NoteTakingHelper::Observer { 94 class TestObserver : public NoteTakingHelper::Observer {
87 public: 95 public:
88 TestObserver() { NoteTakingHelper::Get()->AddObserver(this); } 96 TestObserver() { NoteTakingHelper::Get()->AddObserver(this); }
89 ~TestObserver() override { NoteTakingHelper::Get()->RemoveObserver(this); } 97 ~TestObserver() override { NoteTakingHelper::Get()->RemoveObserver(this); }
90 98
91 int num_updates() const { return num_updates_; } 99 int num_updates() const { return num_updates_; }
100 void reset_num_updates() { num_updates_ = 0; }
92 101
93 private: 102 private:
94 // NoteTakingHelper::Observer: 103 // NoteTakingHelper::Observer:
95 void OnAvailableNoteTakingAppsUpdated() override { num_updates_++; } 104 void OnAvailableNoteTakingAppsUpdated() override { num_updates_++; }
96 105
97 // Number of times that OnAvailableNoteTakingAppsUpdated() has been called. 106 // Number of times that OnAvailableNoteTakingAppsUpdated() has been called.
98 int num_updates_ = 0; 107 int num_updates_ = 0;
99 108
100 DISALLOW_COPY_AND_ASSIGN(TestObserver); 109 DISALLOW_COPY_AND_ASSIGN(TestObserver);
101 }; 110 };
102 111
103 } // namespace 112 } // namespace
104 113
105 class NoteTakingHelperTest : public BrowserWithTestWindowTest { 114 class NoteTakingHelperTest : public BrowserWithTestWindowTest {
106 public: 115 public:
107 NoteTakingHelperTest() = default; 116 NoteTakingHelperTest() = default;
108 ~NoteTakingHelperTest() override = default; 117 ~NoteTakingHelperTest() override = default;
109 118
110 void SetUp() override { 119 void SetUp() override {
111 // This is needed to avoid log spam due to ArcSessionManager's 120 // This is needed to avoid log spam due to ArcSessionManager's
112 // RemoveArcData() calls failing. 121 // RemoveArcData() calls failing.
113 if (DBusThreadManager::IsInitialized()) 122 if (DBusThreadManager::IsInitialized())
114 DBusThreadManager::Shutdown(); 123 DBusThreadManager::Shutdown();
115 session_manager_client_ = new FakeSessionManagerClient(); 124 session_manager_client_ = new FakeSessionManagerClient();
116 session_manager_client_->set_arc_available(true); 125 session_manager_client_->set_arc_available(true);
117 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 126 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
118 std::unique_ptr<SessionManagerClient>(session_manager_client_)); 127 std::unique_ptr<SessionManagerClient>(session_manager_client_));
119 128
129 profile_manager_.reset(
130 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
131 ASSERT_TRUE(profile_manager_->SetUp());
120 BrowserWithTestWindowTest::SetUp(); 132 BrowserWithTestWindowTest::SetUp();
121 133 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 } 134 }
130 135
131 void TearDown() override { 136 void TearDown() override {
132 if (initialized_) { 137 if (initialized_) {
133 NoteTakingHelper::Shutdown(); 138 NoteTakingHelper::Shutdown();
134 arc_test_.TearDown(); 139 arc_test_.TearDown();
135 } 140 }
136 extensions::ExtensionSystem::Get(profile())->Shutdown(); 141 extensions::ExtensionSystem::Get(profile())->Shutdown();
137 BrowserWithTestWindowTest::TearDown(); 142 BrowserWithTestWindowTest::TearDown();
138 DBusThreadManager::Shutdown(); 143 DBusThreadManager::Shutdown();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 .Build()) 201 .Build())
197 .Build()) 202 .Build())
198 .Build()) 203 .Build())
199 .Build(); 204 .Build();
200 return extensions::ExtensionBuilder() 205 return extensions::ExtensionBuilder()
201 .SetManifest(std::move(manifest)) 206 .SetManifest(std::move(manifest))
202 .SetID(id) 207 .SetID(id)
203 .Build(); 208 .Build();
204 } 209 }
205 210
206 // Installs or uninstalls the passed-in extension. 211 // Initializes extensions-related objects for |profile|. Tests only need to
207 void InstallExtension(const extensions::Extension* extension) { 212 // call this if they create additional profiles of their own.
208 extensions::ExtensionSystem::Get(profile()) 213 void InitExtensionService(Profile* profile) {
214 extensions::TestExtensionSystem* extension_system =
215 static_cast<extensions::TestExtensionSystem*>(
216 extensions::ExtensionSystem::Get(profile));
217 extension_system->CreateExtensionService(
218 base::CommandLine::ForCurrentProcess(),
219 base::FilePath() /* install_directory */,
220 false /* autoupdate_enabled */);
221 }
222
223 // Installs or uninstalls |extension| in |profile|.
224 void InstallExtension(const extensions::Extension* extension,
225 Profile* profile) {
226 extensions::ExtensionSystem::Get(profile)
209 ->extension_service() 227 ->extension_service()
210 ->AddExtension(extension); 228 ->AddExtension(extension);
211 } 229 }
212 void UninstallExtension(const extensions::Extension* extension) { 230 void UninstallExtension(const extensions::Extension* extension,
213 extensions::ExtensionSystem::Get(profile()) 231 Profile* profile) {
232 extensions::ExtensionSystem::Get(profile)
214 ->extension_service() 233 ->extension_service()
215 ->UnloadExtension(extension->id(), 234 ->UnloadExtension(extension->id(),
216 extensions::UnloadedExtensionInfo::REASON_UNINSTALL); 235 extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
217 } 236 }
218 237
238 // BrowserWithTestWindowTest:
239 TestingProfile* CreateProfile() override {
240 // Ensure that the profile created by BrowserWithTestWindowTest is
241 // registered with |profile_manager_|.
242 return profile_manager_->CreateTestingProfile(kTestProfileName);
243 }
244 void DestroyProfile(TestingProfile* profile) override {
245 return profile_manager_->DeleteTestingProfile(kTestProfileName);
246 }
247
219 // Info about launched Chrome apps, in the order they were launched. 248 // Info about launched Chrome apps, in the order they were launched.
220 std::vector<ChromeAppLaunchInfo> launched_chrome_apps_; 249 std::vector<ChromeAppLaunchInfo> launched_chrome_apps_;
221 250
222 arc::FakeIntentHelperInstance intent_helper_; 251 arc::FakeIntentHelperInstance intent_helper_;
252 std::unique_ptr<TestingProfileManager> profile_manager_;
223 253
224 private: 254 private:
225 // Callback registered with the helper to record Chrome app launch requests. 255 // Callback registered with the helper to record Chrome app launch requests.
226 void LaunchChromeApp(Profile* passed_profile, 256 void LaunchChromeApp(Profile* passed_profile,
227 const extensions::Extension* extension, 257 const extensions::Extension* extension,
228 std::unique_ptr<app_runtime::ActionData> action_data, 258 std::unique_ptr<app_runtime::ActionData> action_data,
229 const base::FilePath& path) { 259 const base::FilePath& path) {
230 EXPECT_EQ(profile(), passed_profile); 260 EXPECT_EQ(profile(), passed_profile);
231 EXPECT_EQ(app_runtime::ActionType::ACTION_TYPE_NEW_NOTE, 261 EXPECT_EQ(app_runtime::ActionType::ACTION_TYPE_NEW_NOTE,
232 action_data->action_type); 262 action_data->action_type);
233 launched_chrome_apps_.push_back(ChromeAppLaunchInfo{extension->id(), path}); 263 launched_chrome_apps_.push_back(ChromeAppLaunchInfo{extension->id(), path});
234 } 264 }
235 265
236 // Has Init() been called? 266 // Has Init() been called?
237 bool initialized_ = false; 267 bool initialized_ = false;
238 268
239 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned. 269 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned.
240
241 ArcAppTest arc_test_; 270 ArcAppTest arc_test_;
242 271
243 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest); 272 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest);
244 }; 273 };
245 274
246 TEST_F(NoteTakingHelperTest, PaletteNotEnabled) { 275 TEST_F(NoteTakingHelperTest, PaletteNotEnabled) {
247 // Without the palette enabled, IsAppAvailable() should return false. 276 // Without the palette enabled, IsAppAvailable() should return false.
248 Init(0); 277 Init(0);
249 auto extension = 278 auto extension =
250 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); 279 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
251 InstallExtension(extension.get()); 280 InstallExtension(extension.get(), profile());
252 EXPECT_FALSE(helper()->IsAppAvailable(profile())); 281 EXPECT_FALSE(helper()->IsAppAvailable(profile()));
253 } 282 }
254 283
255 TEST_F(NoteTakingHelperTest, ListChromeApps) { 284 TEST_F(NoteTakingHelperTest, ListChromeApps) {
256 Init(ENABLE_PALETTE); 285 Init(ENABLE_PALETTE);
257 286
258 // Start out without any note-taking apps installed. 287 // Start out without any note-taking apps installed.
259 EXPECT_FALSE(helper()->IsAppAvailable(profile())); 288 EXPECT_FALSE(helper()->IsAppAvailable(profile()));
260 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); 289 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty());
261 290
262 // If only the prod version of the app is installed, it should be returned. 291 // If only the prod version of the app is installed, it should be returned.
263 const std::string kProdName = "Google Keep [prod]"; 292 const std::string kProdName = "Google Keep [prod]";
264 auto prod_extension = 293 auto prod_extension =
265 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName); 294 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName);
266 InstallExtension(prod_extension.get()); 295 InstallExtension(prod_extension.get(), profile());
267 EXPECT_TRUE(helper()->IsAppAvailable(profile())); 296 EXPECT_TRUE(helper()->IsAppAvailable(profile()));
268 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); 297 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile());
269 ASSERT_EQ(1u, apps.size()); 298 ASSERT_EQ(1u, apps.size());
270 EXPECT_EQ( 299 EXPECT_EQ(
271 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 300 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
272 GetAppString(apps[0])); 301 GetAppString(apps[0]));
273 302
274 // If the dev version is also installed, it should be listed before the prod 303 // If the dev version is also installed, it should be listed before the prod
275 // version. 304 // version.
276 const std::string kDevName = "Google Keep [dev]"; 305 const std::string kDevName = "Google Keep [dev]";
277 auto dev_extension = 306 auto dev_extension =
278 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, kDevName); 307 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, kDevName);
279 InstallExtension(dev_extension.get()); 308 InstallExtension(dev_extension.get(), profile());
280 apps = helper()->GetAvailableApps(profile()); 309 apps = helper()->GetAvailableApps(profile());
281 ASSERT_EQ(2u, apps.size()); 310 ASSERT_EQ(2u, apps.size());
282 EXPECT_EQ( 311 EXPECT_EQ(
283 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 312 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
284 GetAppString(apps[0])); 313 GetAppString(apps[0]));
285 EXPECT_EQ( 314 EXPECT_EQ(
286 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 315 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
287 GetAppString(apps[1])); 316 GetAppString(apps[1]));
288 317
289 // Now install a random extension and check that it's ignored. 318 // Now install a random extension and check that it's ignored.
290 const extensions::ExtensionId kOtherId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 319 const extensions::ExtensionId kOtherId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
291 const std::string kOtherName = "Some Other App"; 320 const std::string kOtherName = "Some Other App";
292 auto other_extension = CreateExtension(kOtherId, kOtherName); 321 auto other_extension = CreateExtension(kOtherId, kOtherName);
293 InstallExtension(other_extension.get()); 322 InstallExtension(other_extension.get(), profile());
294 apps = helper()->GetAvailableApps(profile()); 323 apps = helper()->GetAvailableApps(profile());
295 ASSERT_EQ(2u, apps.size()); 324 ASSERT_EQ(2u, apps.size());
296 EXPECT_EQ( 325 EXPECT_EQ(
297 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 326 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
298 GetAppString(apps[0])); 327 GetAppString(apps[0]));
299 EXPECT_EQ( 328 EXPECT_EQ(
300 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false), 329 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, false),
301 GetAppString(apps[1])); 330 GetAppString(apps[1]));
302 331
303 // Mark the prod version as preferred. 332 // Mark the prod version as preferred.
304 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId); 333 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId);
305 apps = helper()->GetAvailableApps(profile()); 334 apps = helper()->GetAvailableApps(profile());
306 ASSERT_EQ(2u, apps.size()); 335 ASSERT_EQ(2u, apps.size());
307 EXPECT_EQ( 336 EXPECT_EQ(
308 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), 337 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false),
309 GetAppString(apps[0])); 338 GetAppString(apps[0]));
310 EXPECT_EQ( 339 EXPECT_EQ(
311 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), 340 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true),
312 GetAppString(apps[1])); 341 GetAppString(apps[1]));
313 } 342 }
314 343
315 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { 344 TEST_F(NoteTakingHelperTest, LaunchChromeApp) {
316 Init(ENABLE_PALETTE); 345 Init(ENABLE_PALETTE);
317 auto extension = 346 auto extension =
318 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); 347 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
319 InstallExtension(extension.get()); 348 InstallExtension(extension.get(), profile());
320 349
321 // Check the Chrome app is launched with the correct parameters. 350 // Check the Chrome app is launched with the correct parameters.
322 const base::FilePath kPath("/foo/bar/photo.jpg"); 351 const base::FilePath kPath("/foo/bar/photo.jpg");
323 helper()->LaunchAppForNewNote(profile(), kPath); 352 helper()->LaunchAppForNewNote(profile(), kPath);
324 ASSERT_EQ(1u, launched_chrome_apps_.size()); 353 ASSERT_EQ(1u, launched_chrome_apps_.size());
325 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId, 354 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId,
326 launched_chrome_apps_[0].id); 355 launched_chrome_apps_[0].id);
327 EXPECT_EQ(kPath, launched_chrome_apps_[0].path); 356 EXPECT_EQ(kPath, launched_chrome_apps_[0].path);
328 } 357 }
329 358
330 TEST_F(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) { 359 TEST_F(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) {
331 Init(ENABLE_PALETTE); 360 Init(ENABLE_PALETTE);
332 auto prod_extension = 361 auto prod_extension =
333 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod"); 362 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod");
334 InstallExtension(prod_extension.get()); 363 InstallExtension(prod_extension.get(), profile());
335 auto dev_extension = 364 auto dev_extension =
336 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev"); 365 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev");
337 InstallExtension(dev_extension.get()); 366 InstallExtension(dev_extension.get(), profile());
338 367
339 // Set the prod app as the default and check that it's launched. 368 // Set the prod app as the default and check that it's launched.
340 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId); 369 helper()->SetPreferredApp(profile(), NoteTakingHelper::kProdKeepExtensionId);
341 helper()->LaunchAppForNewNote(profile(), base::FilePath()); 370 helper()->LaunchAppForNewNote(profile(), base::FilePath());
342 ASSERT_EQ(1u, launched_chrome_apps_.size()); 371 ASSERT_EQ(1u, launched_chrome_apps_.size());
343 ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId, 372 ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId,
344 launched_chrome_apps_[0].id); 373 launched_chrome_apps_[0].id);
345 374
346 // Now uninstall the prod app and check that we fall back to the dev app. 375 // Now uninstall the prod app and check that we fall back to the dev app.
347 UninstallExtension(prod_extension.get()); 376 UninstallExtension(prod_extension.get(), profile());
348 launched_chrome_apps_.clear(); 377 launched_chrome_apps_.clear();
349 helper()->LaunchAppForNewNote(profile(), base::FilePath()); 378 helper()->LaunchAppForNewNote(profile(), base::FilePath());
350 ASSERT_EQ(1u, launched_chrome_apps_.size()); 379 ASSERT_EQ(1u, launched_chrome_apps_.size());
351 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id); 380 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id);
352 } 381 }
353 382
354 TEST_F(NoteTakingHelperTest, ArcInitiallyDisabled) { 383 TEST_F(NoteTakingHelperTest, ArcInitiallyDisabled) {
355 Init(ENABLE_PALETTE); 384 Init(ENABLE_PALETTE);
356 EXPECT_FALSE(helper()->android_enabled()); 385 EXPECT_FALSE(helper()->android_enabled());
357 EXPECT_FALSE(helper()->android_apps_received()); 386 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)), 498 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kRemovablePath)),
470 GetIntentString(intent_helper_.handled_intents()[0])); 499 GetIntentString(intent_helper_.handled_intents()[0]));
471 500
472 // When a path that isn't accessible to ARC is passed, the request should be 501 // When a path that isn't accessible to ARC is passed, the request should be
473 // dropped. 502 // dropped.
474 intent_helper_.clear_handled_intents(); 503 intent_helper_.clear_handled_intents();
475 helper()->LaunchAppForNewNote(profile(), base::FilePath("/bad/path.jpg")); 504 helper()->LaunchAppForNewNote(profile(), base::FilePath("/bad/path.jpg"));
476 EXPECT_TRUE(intent_helper_.handled_intents().empty()); 505 EXPECT_TRUE(intent_helper_.handled_intents().empty());
477 } 506 }
478 507
479 TEST_F(NoteTakingHelperTest, NotifyObserver) { 508 TEST_F(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) {
480 Init(ENABLE_PALETTE | ENABLE_ARC); 509 Init(ENABLE_PALETTE | ENABLE_ARC);
481 TestObserver observer; 510 TestObserver observer;
482 511
483 // Let the app-fetching callback run and check that the observer is notified. 512 // Let the app-fetching callback run and check that the observer is notified.
484 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
485 EXPECT_EQ(1, observer.num_updates()); 514 EXPECT_EQ(1, observer.num_updates());
486 515
487 // Disabling and enabling ARC should also notify the observer (and enabling 516 // Disabling and enabling ARC should also notify the observer (and enabling
488 // should request apps again). 517 // should request apps again).
489 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 518 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
490 EXPECT_EQ(2, observer.num_updates()); 519 EXPECT_EQ(2, observer.num_updates());
491 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 520 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
492 EXPECT_EQ(3, observer.num_updates()); 521 EXPECT_EQ(3, observer.num_updates());
493 base::RunLoop().RunUntilIdle(); 522 base::RunLoop().RunUntilIdle();
494 EXPECT_EQ(4, observer.num_updates()); 523 EXPECT_EQ(4, observer.num_updates());
495 524
496 // Update intent filters and check that the observer is notified again after 525 // Update intent filters and check that the observer is notified again after
497 // apps are received. 526 // apps are received.
498 helper()->OnIntentFiltersUpdated(); 527 helper()->OnIntentFiltersUpdated();
499 EXPECT_EQ(4, observer.num_updates()); 528 EXPECT_EQ(4, observer.num_updates());
500 base::RunLoop().RunUntilIdle(); 529 base::RunLoop().RunUntilIdle();
501 EXPECT_EQ(5, observer.num_updates()); 530 EXPECT_EQ(5, observer.num_updates());
502 } 531 }
503 532
533 TEST_F(NoteTakingHelperTest, NotifyObserverAboutChromeApps) {
534 Init(ENABLE_PALETTE);
535 TestObserver observer;
536 ASSERT_EQ(0, observer.num_updates());
537
538 // Notify that the prod Keep app was installed for the initial profile. Chrome
539 // extensions are queried dynamically when GetAvailableApps() is called, so we
540 // don't need to actually install it.
541 auto keep_extension =
542 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
543 InstallExtension(keep_extension.get(), profile());
544 EXPECT_EQ(1, observer.num_updates());
545
546 // Unloading the extension should also trigger a notification.
547 UninstallExtension(keep_extension.get(), profile());
548 EXPECT_EQ(2, observer.num_updates());
549
550 // Non-whitelisted apps shouldn't trigger notifications.
551 auto other_extension =
552 CreateExtension("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Some Other App");
553 InstallExtension(other_extension.get(), profile());
554 EXPECT_EQ(2, observer.num_updates());
555 UninstallExtension(other_extension.get(), profile());
556 EXPECT_EQ(2, observer.num_updates());
557
558 // Add a second profile and check that it triggers notifications too.
559 observer.reset_num_updates();
560 const std::string kSecondProfileName = "second-profile";
561 TestingProfile* second_profile =
562 profile_manager_->CreateTestingProfile(kSecondProfileName);
563 InitExtensionService(second_profile);
564 EXPECT_EQ(0, observer.num_updates());
565 InstallExtension(keep_extension.get(), second_profile);
566 EXPECT_EQ(1, observer.num_updates());
567 UninstallExtension(keep_extension.get(), second_profile);
568 EXPECT_EQ(2, observer.num_updates());
569 profile_manager_->DeleteTestingProfile(kSecondProfileName);
570 }
571
504 } // namespace chromeos 572 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/note_taking_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698