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