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

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

Issue 15932010: drive: Rename DriveWebApp* to DriveApp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 6 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_webapps_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/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/chromeos/drive/job_scheduler.h" 13 #include "chrome/browser/chromeos/drive/job_scheduler.h"
14 #include "chrome/browser/chromeos/drive/test_util.h" 14 #include "chrome/browser/chromeos/drive/test_util.h"
15 #include "chrome/browser/google_apis/drive_api_parser.h" 15 #include "chrome/browser/google_apis/drive_api_parser.h"
16 #include "chrome/browser/google_apis/fake_drive_service.h" 16 #include "chrome/browser/google_apis/fake_drive_service.h"
17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
18 #include "chrome/browser/google_apis/test_util.h" 18 #include "chrome/browser/google_apis/test_util.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using base::Value; 24 using base::Value;
25 using base::DictionaryValue; 25 using base::DictionaryValue;
26 using base::ListValue; 26 using base::ListValue;
27 27
28 namespace drive { 28 namespace drive {
29 29
30 class DriveWebAppsRegistryTest : public testing::Test { 30 class DriveAppRegistryTest : public testing::Test {
31 protected: 31 protected:
32 DriveWebAppsRegistryTest() 32 DriveAppRegistryTest()
33 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 33 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
34 } 34 }
35 35
36 virtual void SetUp() OVERRIDE { 36 virtual void SetUp() OVERRIDE {
37 profile_.reset(new TestingProfile); 37 profile_.reset(new TestingProfile);
38 38
39 // The fake object will be manually deleted in TearDown(). 39 // The fake object will be manually deleted in TearDown().
40 fake_drive_service_.reset(new google_apis::FakeDriveService); 40 fake_drive_service_.reset(new google_apis::FakeDriveService);
41 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json"); 41 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json");
42 42
43 scheduler_.reset( 43 scheduler_.reset(
44 new JobScheduler(profile_.get(), fake_drive_service_.get())); 44 new JobScheduler(profile_.get(), fake_drive_service_.get()));
45 45
46 web_apps_registry_.reset(new DriveWebAppsRegistry(scheduler_.get())); 46 web_apps_registry_.reset(new DriveAppRegistry(scheduler_.get()));
47 web_apps_registry_->Update(); 47 web_apps_registry_->Update();
48 google_apis::test_util::RunBlockingPoolTask(); 48 google_apis::test_util::RunBlockingPoolTask();
49 } 49 }
50 50
51 bool VerifyApp(const ScopedVector<DriveWebAppInfo>& list, 51 bool VerifyApp(const ScopedVector<DriveAppInfo>& list,
52 const std::string& web_store_id, 52 const std::string& web_store_id,
53 const std::string& app_id, 53 const std::string& app_id,
54 const std::string& app_name, 54 const std::string& app_name,
55 const std::string& object_type, 55 const std::string& object_type,
56 bool is_primary) { 56 bool is_primary) {
57 bool found = false; 57 bool found = false;
58 for (ScopedVector<DriveWebAppInfo>::const_iterator it = list.begin(); 58 for (ScopedVector<DriveAppInfo>::const_iterator it = list.begin();
59 it != list.end(); ++it) { 59 it != list.end(); ++it) {
60 const DriveWebAppInfo* app = *it; 60 const DriveAppInfo* app = *it;
61 if (web_store_id == app->web_store_id) { 61 if (web_store_id == app->web_store_id) {
62 EXPECT_EQ(app_id, app->app_id); 62 EXPECT_EQ(app_id, app->app_id);
63 EXPECT_EQ(app_name, UTF16ToUTF8(app->app_name)); 63 EXPECT_EQ(app_name, UTF16ToUTF8(app->app_name));
64 EXPECT_EQ(object_type, UTF16ToUTF8(app->object_type)); 64 EXPECT_EQ(object_type, UTF16ToUTF8(app->object_type));
65 EXPECT_EQ(is_primary, app->is_primary_selector); 65 EXPECT_EQ(is_primary, app->is_primary_selector);
66 found = true; 66 found = true;
67 break; 67 break;
68 } 68 }
69 } 69 }
70 EXPECT_TRUE(found) << "Unable to find app with web_store_id " 70 EXPECT_TRUE(found) << "Unable to find app with web_store_id "
71 << web_store_id; 71 << web_store_id;
72 return found; 72 return found;
73 } 73 }
74 74
75 bool VerifyApp1(const ScopedVector<DriveWebAppInfo>& list, 75 bool VerifyApp1(const ScopedVector<DriveAppInfo>& list,
76 bool is_primary) { 76 bool is_primary) {
77 return VerifyApp(list, "abcdefabcdef", "11111111", 77 return VerifyApp(list, "abcdefabcdef", "11111111",
78 "Drive App 1", "Drive App Object 1", 78 "Drive App 1", "Drive App Object 1",
79 is_primary); 79 is_primary);
80 } 80 }
81 81
82 bool VerifyApp2(const ScopedVector<DriveWebAppInfo>& list, 82 bool VerifyApp2(const ScopedVector<DriveAppInfo>& list,
83 bool is_primary) { 83 bool is_primary) {
84 return VerifyApp(list, "deadbeefdeadbeef", "22222222", 84 return VerifyApp(list, "deadbeefdeadbeef", "22222222",
85 "Drive App 2", "Drive App Object 2", 85 "Drive App 2", "Drive App Object 2",
86 is_primary); 86 is_primary);
87 } 87 }
88 88
89 MessageLoopForUI message_loop_; 89 MessageLoopForUI message_loop_;
90 content::TestBrowserThread ui_thread_; 90 content::TestBrowserThread ui_thread_;
91 91
92 scoped_ptr<TestingProfile> profile_; 92 scoped_ptr<TestingProfile> profile_;
93 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 93 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
94 scoped_ptr<JobScheduler> scheduler_; 94 scoped_ptr<JobScheduler> scheduler_;
95 scoped_ptr<DriveWebAppsRegistry> web_apps_registry_; 95 scoped_ptr<DriveAppRegistry> web_apps_registry_;
96 }; 96 };
97 97
98 TEST_F(DriveWebAppsRegistryTest, LoadAndFindDriveWebApps) { 98 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) {
99 // Find by primary extension 'exe'. 99 // Find by primary extension 'exe'.
100 ScopedVector<DriveWebAppInfo> ext_results; 100 ScopedVector<DriveAppInfo> ext_results;
101 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); 101 base::FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe"));
102 web_apps_registry_->GetWebAppsForFile(ext_file, std::string(), &ext_results); 102 web_apps_registry_->GetAppsForFile(ext_file, std::string(), &ext_results);
103 ASSERT_EQ(1U, ext_results.size()); 103 ASSERT_EQ(1U, ext_results.size());
104 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 104 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
105 "Drive app 1", "", true); 105 "Drive app 1", "", true);
106 106
107 // Find by primary MIME type. 107 // Find by primary MIME type.
108 ScopedVector<DriveWebAppInfo> primary_app; 108 ScopedVector<DriveAppInfo> primary_app;
109 web_apps_registry_->GetWebAppsForFile(base::FilePath(), 109 web_apps_registry_->GetAppsForFile(base::FilePath(),
110 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); 110 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app);
111 ASSERT_EQ(1U, primary_app.size()); 111 ASSERT_EQ(1U, primary_app.size());
112 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 112 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
113 "Drive app 1", "", true); 113 "Drive app 1", "", true);
114 114
115 // Find by secondary MIME type. 115 // Find by secondary MIME type.
116 ScopedVector<DriveWebAppInfo> secondary_app; 116 ScopedVector<DriveAppInfo> secondary_app;
117 web_apps_registry_->GetWebAppsForFile( 117 web_apps_registry_->GetAppsForFile(
118 base::FilePath(), "text/html", &secondary_app); 118 base::FilePath(), "text/html", &secondary_app);
119 ASSERT_EQ(1U, secondary_app.size()); 119 ASSERT_EQ(1U, secondary_app.size());
120 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", 120 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
121 "Drive app 1", "", false); 121 "Drive app 1", "", false);
122 } 122 }
123 123
124 } // namespace drive 124 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_app_registry.cc ('k') | chrome/browser/chromeos/drive/drive_integration_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698