OLD | NEW |
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" | |
9 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
10 #include "chrome/browser/chromeos/drive/job_scheduler.h" | |
11 #include "chrome/browser/chromeos/drive/test_util.h" | |
12 #include "chrome/browser/drive/fake_drive_service.h" | 9 #include "chrome/browser/drive/fake_drive_service.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "google_apis/drive/drive_api_parser.h" | 11 #include "google_apis/drive/drive_api_parser.h" |
15 #include "google_apis/drive/gdata_wapi_parser.h" | 12 #include "google_apis/drive/gdata_wapi_parser.h" |
16 #include "google_apis/drive/test_util.h" | 13 #include "google_apis/drive/test_util.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
18 | 15 |
19 namespace drive { | 16 namespace drive { |
20 | 17 |
21 class DriveAppRegistryTest : public testing::Test { | 18 class DriveAppRegistryTest : public testing::Test { |
22 protected: | 19 protected: |
23 virtual void SetUp() OVERRIDE { | 20 virtual void SetUp() OVERRIDE { |
24 pref_service_.reset(new TestingPrefServiceSimple); | |
25 test_util::RegisterDrivePrefs(pref_service_->registry()); | |
26 | |
27 fake_drive_service_.reset(new FakeDriveService); | 21 fake_drive_service_.reset(new FakeDriveService); |
28 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | 22 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); |
29 | 23 |
30 scheduler_.reset(new JobScheduler(pref_service_.get(), | 24 apps_registry_.reset(new DriveAppRegistry(fake_drive_service_.get())); |
31 fake_drive_service_.get(), | |
32 base::MessageLoopProxy::current().get())); | |
33 | |
34 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get())); | |
35 } | 25 } |
36 | 26 |
37 bool VerifyApp(const ScopedVector<DriveAppInfo>& list, | 27 bool VerifyApp(const std::vector<DriveAppInfo>& list, |
38 const std::string& app_id, | 28 const std::string& app_id, |
39 const std::string& app_name) { | 29 const std::string& app_name) { |
40 bool found = false; | 30 bool found = false; |
41 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin(); | 31 for (size_t i = 0; i < list.size(); ++i) { |
42 it != list.end(); ++it) { | 32 const DriveAppInfo& app = list[i]; |
43 const DriveAppInfo* app = *it; | 33 if (app_id == app.app_id) { |
44 if (app_id == app->app_id) { | 34 EXPECT_EQ(app_name, app.app_name); |
45 EXPECT_EQ(app_name, app->app_name); | |
46 found = true; | 35 found = true; |
47 break; | 36 break; |
48 } | 37 } |
49 } | 38 } |
50 EXPECT_TRUE(found) << "Unable to find app with app_id " << app_id; | 39 EXPECT_TRUE(found) << "Unable to find app with app_id " << app_id; |
51 return found; | 40 return found; |
52 } | 41 } |
53 | 42 |
54 content::TestBrowserThreadBundle thread_bundle_; | 43 content::TestBrowserThreadBundle thread_bundle_; |
55 scoped_ptr<TestingPrefServiceSimple> pref_service_; | |
56 scoped_ptr<FakeDriveService> fake_drive_service_; | 44 scoped_ptr<FakeDriveService> fake_drive_service_; |
57 scoped_ptr<JobScheduler> scheduler_; | 45 scoped_ptr<DriveAppRegistry> apps_registry_; |
58 scoped_ptr<DriveAppRegistry> web_apps_registry_; | |
59 }; | 46 }; |
60 | 47 |
61 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) { | 48 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) { |
62 web_apps_registry_->Update(); | 49 apps_registry_->Update(); |
63 base::RunLoop().RunUntilIdle(); | 50 base::RunLoop().RunUntilIdle(); |
64 | 51 |
65 // Find by primary extension 'exe'. | 52 // Find by primary extension 'exe'. |
66 ScopedVector<DriveAppInfo> ext_results; | 53 std::vector<DriveAppInfo> ext_results; |
67 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); | 54 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); |
68 web_apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results); | 55 apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results); |
69 ASSERT_EQ(1U, ext_results.size()); | 56 ASSERT_EQ(1U, ext_results.size()); |
70 VerifyApp(ext_results, "123456788192", "Drive app 1"); | 57 VerifyApp(ext_results, "123456788192", "Drive app 1"); |
71 | 58 |
72 // Find by primary MIME type. | 59 // Find by primary MIME type. |
73 ScopedVector<DriveAppInfo> primary_app; | 60 std::vector<DriveAppInfo> primary_app; |
74 web_apps_registry_->GetAppsForFile(base::FilePath::StringType(), | 61 apps_registry_->GetAppsForFile(base::FilePath::StringType(), |
75 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); | 62 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); |
76 ASSERT_EQ(1U, primary_app.size()); | 63 ASSERT_EQ(1U, primary_app.size()); |
77 VerifyApp(primary_app, "123456788192", "Drive app 1"); | 64 VerifyApp(primary_app, "123456788192", "Drive app 1"); |
78 | 65 |
79 // Find by secondary MIME type. | 66 // Find by secondary MIME type. |
80 ScopedVector<DriveAppInfo> secondary_app; | 67 std::vector<DriveAppInfo> secondary_app; |
81 web_apps_registry_->GetAppsForFile( | 68 apps_registry_->GetAppsForFile( |
82 base::FilePath::StringType(), "text/html", &secondary_app); | 69 base::FilePath::StringType(), "text/html", &secondary_app); |
83 ASSERT_EQ(1U, secondary_app.size()); | 70 ASSERT_EQ(1U, secondary_app.size()); |
84 VerifyApp(secondary_app, "123456788192", "Drive app 1"); | 71 VerifyApp(secondary_app, "123456788192", "Drive app 1"); |
85 } | 72 } |
86 | 73 |
87 TEST_F(DriveAppRegistryTest, UpdateFromAppList) { | 74 TEST_F(DriveAppRegistryTest, UpdateFromAppList) { |
88 scoped_ptr<base::Value> app_info_value = | 75 scoped_ptr<base::Value> app_info_value = |
89 google_apis::test_util::LoadJSONFile("drive/applist.json"); | 76 google_apis::test_util::LoadJSONFile("drive/applist.json"); |
90 scoped_ptr<google_apis::AppList> app_list( | 77 scoped_ptr<google_apis::AppList> app_list( |
91 google_apis::AppList::CreateFrom(*app_info_value)); | 78 google_apis::AppList::CreateFrom(*app_info_value)); |
92 | 79 |
93 web_apps_registry_->UpdateFromAppList(*app_list); | 80 apps_registry_->UpdateFromAppList(*app_list); |
94 | 81 |
95 // Confirm that something was loaded from applist.json. | 82 // Confirm that something was loaded from applist.json. |
96 ScopedVector<DriveAppInfo> ext_results; | 83 std::vector<DriveAppInfo> ext_results; |
97 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); | 84 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); |
98 web_apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results); | 85 apps_registry_->GetAppsForFile(ext_file.Extension(), "", &ext_results); |
99 ASSERT_EQ(1U, ext_results.size()); | 86 ASSERT_EQ(1U, ext_results.size()); |
100 } | 87 } |
101 | 88 |
102 TEST_F(DriveAppRegistryTest, MultipleUpdate) { | 89 TEST_F(DriveAppRegistryTest, MultipleUpdate) { |
103 // Call Update(). | 90 // Call Update(). |
104 web_apps_registry_->Update(); | 91 apps_registry_->Update(); |
105 | 92 |
106 // Call Update() again. | 93 // Call Update() again. |
107 // This call should be ignored because there is already an ongoing update. | 94 // This call should be ignored because there is already an ongoing update. |
108 web_apps_registry_->Update(); | 95 apps_registry_->Update(); |
109 | 96 |
110 // The app list should be loaded only once. | 97 // The app list should be loaded only once. |
111 base::RunLoop().RunUntilIdle(); | 98 base::RunLoop().RunUntilIdle(); |
112 EXPECT_EQ(1, fake_drive_service_->app_list_load_count()); | 99 EXPECT_EQ(1, fake_drive_service_->app_list_load_count()); |
113 } | 100 } |
114 | 101 |
115 TEST(DriveAppRegistryUtilTest, FindPreferredIcon_Empty) { | 102 TEST(DriveAppRegistryUtilTest, FindPreferredIcon_Empty) { |
116 google_apis::InstalledApp::IconList icons; | 103 google_apis::InstalledApp::IconList icons; |
117 EXPECT_EQ("", | 104 EXPECT_EQ("", |
118 util::FindPreferredIcon(icons, util::kPreferredIconSize).spec()); | 105 util::FindPreferredIcon(icons, util::kPreferredIconSize).spec()); |
(...skipping 25 matching lines...) Expand all Loading... |
144 // should be returned. | 131 // should be returned. |
145 EXPECT_EQ(kSmallerIconUrl, | 132 EXPECT_EQ(kSmallerIconUrl, |
146 util::FindPreferredIcon(icons, kMediumSize - 3).spec()); | 133 util::FindPreferredIcon(icons, kMediumSize - 3).spec()); |
147 // The requested size is larger than the largest icon. The largest icon | 134 // The requested size is larger than the largest icon. The largest icon |
148 // should be returned. | 135 // should be returned. |
149 EXPECT_EQ(kBiggerIconUrl, | 136 EXPECT_EQ(kBiggerIconUrl, |
150 util::FindPreferredIcon(icons, kMediumSize + 3).spec()); | 137 util::FindPreferredIcon(icons, kMediumSize + 3).spec()); |
151 } | 138 } |
152 | 139 |
153 } // namespace drive | 140 } // namespace drive |
OLD | NEW |