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

Side by Side Diff: chrome/browser/chromeos/drive/drive_app_registry_unittest.cc

Issue 22297004: drive: Stop making multiple GetAppList() requests from DriveAppRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/drive/drive_app_registry.h" 5 #include "chrome/browser/chromeos/drive/drive_app_registry.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 12 matching lines...) Expand all
23 test_util::RegisterDrivePrefs(pref_service_->registry()); 23 test_util::RegisterDrivePrefs(pref_service_->registry());
24 24
25 fake_drive_service_.reset(new FakeDriveService); 25 fake_drive_service_.reset(new FakeDriveService);
26 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); 26 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
27 27
28 scheduler_.reset(new JobScheduler(pref_service_.get(), 28 scheduler_.reset(new JobScheduler(pref_service_.get(),
29 fake_drive_service_.get(), 29 fake_drive_service_.get(),
30 base::MessageLoopProxy::current().get())); 30 base::MessageLoopProxy::current().get()));
31 31
32 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get())); 32 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get()));
33 web_apps_registry_->Update();
34 base::RunLoop().RunUntilIdle();
35 } 33 }
36 34
37 bool VerifyApp(const ScopedVector<DriveAppInfo>& list, 35 bool VerifyApp(const ScopedVector<DriveAppInfo>& list,
38 const std::string& web_store_id, 36 const std::string& web_store_id,
39 const std::string& app_id, 37 const std::string& app_id,
40 const std::string& app_name, 38 const std::string& app_name,
41 const std::string& object_type, 39 const std::string& object_type,
42 bool is_primary) { 40 bool is_primary) {
43 bool found = false; 41 bool found = false;
44 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin(); 42 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin();
45 it != list.end(); ++it) { 43 it != list.end(); ++it) {
46 const DriveAppInfo* app = *it; 44 const DriveAppInfo* app = *it;
47 if (web_store_id == app->web_store_id) { 45 if (web_store_id == app->web_store_id) {
48 EXPECT_EQ(app_id, app->app_id); 46 EXPECT_EQ(app_id, app->app_id);
49 EXPECT_EQ(app_name, UTF16ToUTF8(app->app_name)); 47 EXPECT_EQ(app_name, UTF16ToUTF8(app->app_name));
50 EXPECT_EQ(object_type, UTF16ToUTF8(app->object_type)); 48 EXPECT_EQ(object_type, UTF16ToUTF8(app->object_type));
51 EXPECT_EQ(is_primary, app->is_primary_selector); 49 EXPECT_EQ(is_primary, app->is_primary_selector);
52 found = true; 50 found = true;
53 break; 51 break;
54 } 52 }
55 } 53 }
56 EXPECT_TRUE(found) << "Unable to find app with web_store_id " 54 EXPECT_TRUE(found) << "Unable to find app with web_store_id "
57 << web_store_id; 55 << web_store_id;
58 return found; 56 return found;
59 } 57 }
60 58
61 content::TestBrowserThreadBundle thread_bundle_; 59 content::TestBrowserThreadBundle thread_bundle_;
62 scoped_ptr<TestingPrefServiceSimple> pref_service_; 60 scoped_ptr<TestingPrefServiceSimple> pref_service_;
63 scoped_ptr<FakeDriveService> fake_drive_service_; 61 scoped_ptr<FakeDriveService> fake_drive_service_;
64 scoped_ptr<JobScheduler> scheduler_; 62 scoped_ptr<JobScheduler> scheduler_;
65 scoped_ptr<DriveAppRegistry> web_apps_registry_; 63 scoped_ptr<DriveAppRegistry> web_apps_registry_;
66 }; 64 };
67 65
68 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) { 66 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) {
67 web_apps_registry_->Update();
68 base::RunLoop().RunUntilIdle();
69
69 // Find by primary extension 'exe'. 70 // Find by primary extension 'exe'.
70 ScopedVector<DriveAppInfo> ext_results; 71 ScopedVector<DriveAppInfo> ext_results;
71 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); 72 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe"));
72 web_apps_registry_->GetAppsForFile(ext_file, std::string(), &ext_results); 73 web_apps_registry_->GetAppsForFile(ext_file, std::string(), &ext_results);
73 ASSERT_EQ(1U, ext_results.size()); 74 ASSERT_EQ(1U, ext_results.size());
74 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 75 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
75 "Drive app 1", "", true); 76 "Drive app 1", "", true);
76 77
77 // Find by primary MIME type. 78 // Find by primary MIME type.
78 ScopedVector<DriveAppInfo> primary_app; 79 ScopedVector<DriveAppInfo> primary_app;
79 web_apps_registry_->GetAppsForFile(base::FilePath(), 80 web_apps_registry_->GetAppsForFile(base::FilePath(),
80 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); 81 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app);
81 ASSERT_EQ(1U, primary_app.size()); 82 ASSERT_EQ(1U, primary_app.size());
82 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 83 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
83 "Drive app 1", "", true); 84 "Drive app 1", "", true);
84 85
85 // Find by secondary MIME type. 86 // Find by secondary MIME type.
86 ScopedVector<DriveAppInfo> secondary_app; 87 ScopedVector<DriveAppInfo> secondary_app;
87 web_apps_registry_->GetAppsForFile( 88 web_apps_registry_->GetAppsForFile(
88 base::FilePath(), "text/html", &secondary_app); 89 base::FilePath(), "text/html", &secondary_app);
89 ASSERT_EQ(1U, secondary_app.size()); 90 ASSERT_EQ(1U, secondary_app.size());
90 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 91 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
91 "Drive app 1", "", false); 92 "Drive app 1", "", false);
92 } 93 }
93 94
95 TEST_F(DriveAppRegistryTest, MultipleUpdate) {
96 // Call Update().
97 web_apps_registry_->Update();
98
99 // Call Update() again.
100 // This call should be ignored because there is already an ongoing update.
101 web_apps_registry_->Update();
102
103 // The app list should be loaded only once.
104 base::RunLoop().RunUntilIdle();
105 EXPECT_EQ(1, fake_drive_service_->app_list_load_count());
106 }
107
94 } // namespace drive 108 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_app_registry.cc ('k') | chrome/browser/drive/fake_drive_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698