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

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

Issue 125163004: Clean up DriveAppRegistry (part 1 of 2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused helper function. Created 6 years, 11 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
« no previous file with comments | « chrome/browser/chromeos/drive/drive_app_registry.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 (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 "chrome/browser/chromeos/drive/job_scheduler.h" 10 #include "chrome/browser/chromeos/drive/job_scheduler.h"
(...skipping 17 matching lines...) Expand all
28 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); 28 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
29 29
30 scheduler_.reset(new JobScheduler(pref_service_.get(), 30 scheduler_.reset(new JobScheduler(pref_service_.get(),
31 fake_drive_service_.get(), 31 fake_drive_service_.get(),
32 base::MessageLoopProxy::current().get())); 32 base::MessageLoopProxy::current().get()));
33 33
34 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get())); 34 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get()));
35 } 35 }
36 36
37 bool VerifyApp(const ScopedVector<DriveAppInfo>& list, 37 bool VerifyApp(const ScopedVector<DriveAppInfo>& list,
38 const std::string& web_store_id,
39 const std::string& app_id, 38 const std::string& app_id,
40 const std::string& app_name, 39 const std::string& app_name) {
41 const std::string& object_type,
42 bool is_primary) {
43 bool found = false; 40 bool found = false;
44 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin(); 41 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin();
45 it != list.end(); ++it) { 42 it != list.end(); ++it) {
46 const DriveAppInfo* app = *it; 43 const DriveAppInfo* app = *it;
47 if (web_store_id == app->web_store_id) { 44 if (app_id == app->app_id) {
48 EXPECT_EQ(app_id, app->app_id);
49 EXPECT_EQ(app_name, app->app_name); 45 EXPECT_EQ(app_name, app->app_name);
50 EXPECT_EQ(object_type, app->object_type);
51 EXPECT_EQ(is_primary, app->is_primary_selector);
52 found = true; 46 found = true;
53 break; 47 break;
54 } 48 }
55 } 49 }
56 EXPECT_TRUE(found) << "Unable to find app with web_store_id " 50 EXPECT_TRUE(found) << "Unable to find app with app_id " << app_id;
57 << web_store_id;
58 return found; 51 return found;
59 } 52 }
60 53
61 content::TestBrowserThreadBundle thread_bundle_; 54 content::TestBrowserThreadBundle thread_bundle_;
62 scoped_ptr<TestingPrefServiceSimple> pref_service_; 55 scoped_ptr<TestingPrefServiceSimple> pref_service_;
63 scoped_ptr<FakeDriveService> fake_drive_service_; 56 scoped_ptr<FakeDriveService> fake_drive_service_;
64 scoped_ptr<JobScheduler> scheduler_; 57 scoped_ptr<JobScheduler> scheduler_;
65 scoped_ptr<DriveAppRegistry> web_apps_registry_; 58 scoped_ptr<DriveAppRegistry> web_apps_registry_;
66 }; 59 };
67 60
68 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) { 61 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) {
69 web_apps_registry_->Update(); 62 web_apps_registry_->Update();
70 base::RunLoop().RunUntilIdle(); 63 base::RunLoop().RunUntilIdle();
71 64
72 // Find by primary extension 'exe'. 65 // Find by primary extension 'exe'.
73 ScopedVector<DriveAppInfo> ext_results; 66 ScopedVector<DriveAppInfo> ext_results;
74 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); 67 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe"));
75 web_apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results); 68 web_apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results);
76 ASSERT_EQ(1U, ext_results.size()); 69 ASSERT_EQ(1U, ext_results.size());
77 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 70 VerifyApp(ext_results, "123456788192", "Drive app 1");
78 "Drive app 1", "", true);
79 71
80 // Find by primary MIME type. 72 // Find by primary MIME type.
81 ScopedVector<DriveAppInfo> primary_app; 73 ScopedVector<DriveAppInfo> primary_app;
82 web_apps_registry_->GetAppsForFile(base::FilePath::StringType(), 74 web_apps_registry_->GetAppsForFile(base::FilePath::StringType(),
83 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); 75 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app);
84 ASSERT_EQ(1U, primary_app.size()); 76 ASSERT_EQ(1U, primary_app.size());
85 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 77 VerifyApp(primary_app, "123456788192", "Drive app 1");
86 "Drive app 1", "", true);
87 78
88 // Find by secondary MIME type. 79 // Find by secondary MIME type.
89 ScopedVector<DriveAppInfo> secondary_app; 80 ScopedVector<DriveAppInfo> secondary_app;
90 web_apps_registry_->GetAppsForFile( 81 web_apps_registry_->GetAppsForFile(
91 base::FilePath::StringType(), "text/html", &secondary_app); 82 base::FilePath::StringType(), "text/html", &secondary_app);
92 ASSERT_EQ(1U, secondary_app.size()); 83 ASSERT_EQ(1U, secondary_app.size());
93 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 84 VerifyApp(secondary_app, "123456788192", "Drive app 1");
94 "Drive app 1", "", false);
95 } 85 }
96 86
97 TEST_F(DriveAppRegistryTest, UpdateFromAppList) { 87 TEST_F(DriveAppRegistryTest, UpdateFromAppList) {
98 scoped_ptr<base::Value> app_info_value = 88 scoped_ptr<base::Value> app_info_value =
99 google_apis::test_util::LoadJSONFile("drive/applist.json"); 89 google_apis::test_util::LoadJSONFile("drive/applist.json");
100 scoped_ptr<google_apis::AppList> app_list( 90 scoped_ptr<google_apis::AppList> app_list(
101 google_apis::AppList::CreateFrom(*app_info_value)); 91 google_apis::AppList::CreateFrom(*app_info_value));
102 92
103 web_apps_registry_->UpdateFromAppList(*app_list); 93 web_apps_registry_->UpdateFromAppList(*app_list);
104 94
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // should be returned. 144 // should be returned.
155 EXPECT_EQ(kSmallerIconUrl, 145 EXPECT_EQ(kSmallerIconUrl,
156 util::FindPreferredIcon(icons, kMediumSize - 3).spec()); 146 util::FindPreferredIcon(icons, kMediumSize - 3).spec());
157 // The requested size is larger than the largest icon. The largest icon 147 // The requested size is larger than the largest icon. The largest icon
158 // should be returned. 148 // should be returned.
159 EXPECT_EQ(kBiggerIconUrl, 149 EXPECT_EQ(kBiggerIconUrl,
160 util::FindPreferredIcon(icons, kMediumSize + 3).spec()); 150 util::FindPreferredIcon(icons, kMediumSize + 3).spec());
161 } 151 }
162 152
163 } // namespace drive 153 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_app_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698