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

Side by Side Diff: chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc

Issue 10829276: Get web application list using Drive V2 API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 8 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/json/json_file_value_serializer.h" 7 #include "base/json/json_file_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string16.h" 10 #include "base/string16.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/gdata/drive_api_parser.h"
13 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 14 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
14 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" 15 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using base::Value; 20 using base::Value;
20 using base::DictionaryValue; 21 using base::DictionaryValue;
21 using base::ListValue; 22 using base::ListValue;
22 23
23 #define IF_EXPECT_EQ(arg1, arg2) \
24 EXPECT_EQ(arg1, arg2); \
25 if (arg1 == arg2)
26
27 namespace gdata { 24 namespace gdata {
28 25
29 class DriveWebAppsRegistryTest : public testing::Test { 26 class DriveWebAppsRegistryTest : public testing::Test {
30 protected: 27 protected:
31 DriveWebAppsRegistryTest() 28 DriveWebAppsRegistryTest()
32 : ui_thread_(content::BrowserThread::UI, &message_loop_){ 29 : ui_thread_(content::BrowserThread::UI, &message_loop_){
33 } 30 }
34 31
35 static Value* LoadJSONFile(const std::string& filename) { 32 static Value* LoadJSONFile(const std::string& prefix,
33 const std::string& filename) {
36 FilePath path; 34 FilePath path;
37 std::string error; 35 std::string error;
38 // Test files for this unit test are located in 36 // Test files for this unit test are located in
39 // src/chrome/test/data/chromeos/gdata/* 37 // src/chrome/test/data/chromeos/gdata/*
40 PathService::Get(chrome::DIR_TEST_DATA, &path); 38 PathService::Get(chrome::DIR_TEST_DATA, &path);
41 path = path.AppendASCII("chromeos") 39 path = path.AppendASCII("chromeos").AppendASCII(prefix)
42 .AppendASCII("gdata") 40 .AppendASCII(filename);
43 .AppendASCII(filename.c_str());
44 EXPECT_TRUE(file_util::PathExists(path)) << 41 EXPECT_TRUE(file_util::PathExists(path)) <<
45 "Couldn't find " << path.value(); 42 "Couldn't find " << path.value();
46 43
47 JSONFileValueSerializer serializer(path); 44 JSONFileValueSerializer serializer(path);
48 Value* value = serializer.Deserialize(NULL, &error); 45 Value* value = serializer.Deserialize(NULL, &error);
49 EXPECT_TRUE(value) << 46 EXPECT_TRUE(value) <<
50 "Parse error " << path.value() << ": " << error; 47 "Parse error " << path.value() << ": " << error;
51 return value; 48 return value;
52 } 49 }
53 50
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 "Drive App 2", "Drive App Object 2", 85 "Drive App 2", "Drive App Object 2",
89 is_primary); 86 is_primary);
90 } 87 }
91 88
92 private: 89 private:
93 MessageLoopForUI message_loop_; 90 MessageLoopForUI message_loop_;
94 content::TestBrowserThread ui_thread_; 91 content::TestBrowserThread ui_thread_;
95 }; 92 };
96 93
97 TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) { 94 TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) {
98 scoped_ptr<Value> document(LoadJSONFile("account_metadata.json")); 95 scoped_ptr<Value> document(LoadJSONFile("gdata", "account_metadata.json"));
99 ASSERT_TRUE(document.get()); 96 ASSERT_TRUE(document.get());
100 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); 97 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY);
101 DictionaryValue* entry_value; 98 DictionaryValue* entry_value;
102 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary( 99 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary(
103 std::string("entry"), &entry_value)); 100 std::string("entry"), &entry_value));
104 ASSERT_TRUE(entry_value); 101 ASSERT_TRUE(entry_value);
105 102
106 // Load feed. 103 // Load feed.
107 scoped_ptr<AccountMetadataFeed> feed( 104 scoped_ptr<AccountMetadataFeed> feed(
108 AccountMetadataFeed::CreateFrom(*document)); 105 AccountMetadataFeed::CreateFrom(*document));
109 ASSERT_TRUE(feed.get()); 106 ASSERT_TRUE(feed.get());
110 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry); 107 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry);
111 web_apps->UpdateFromFeed(feed.get()); 108 web_apps->UpdateFromFeed(*feed.get());
112 109
113 // Find by extension 'ext_1'. 110 // Find by extension 'ext_1'.
114 ScopedVector<DriveWebAppInfo> ext_1_results; 111 ScopedVector<DriveWebAppInfo> ext_1_results;
115 FilePath ext1_file(FILE_PATH_LITERAL("gdata/SampleFile.ext_1")); 112 FilePath ext1_file(FILE_PATH_LITERAL("gdata/SampleFile.ext_1"));
116 web_apps->GetWebAppsForFile(ext1_file, std::string(), &ext_1_results); 113 web_apps->GetWebAppsForFile(ext1_file, std::string(), &ext_1_results);
117 IF_EXPECT_EQ(1U, ext_1_results.size()) { 114 ASSERT_EQ(1U, ext_1_results.size());
118 EXPECT_TRUE(VerifyApp1(ext_1_results, true)); 115 EXPECT_TRUE(VerifyApp1(ext_1_results, true));
119 }
120 116
121 // Find by extension 'ext_3'. 117 // Find by extension 'ext_3'.
122 ScopedVector<DriveWebAppInfo> ext_3_results; 118 ScopedVector<DriveWebAppInfo> ext_3_results;
123 FilePath ext3_file(FILE_PATH_LITERAL("gdata/AnotherFile.ext_3")); 119 FilePath ext3_file(FILE_PATH_LITERAL("gdata/AnotherFile.ext_3"));
124 web_apps->GetWebAppsForFile(ext3_file, std::string(), &ext_3_results); 120 web_apps->GetWebAppsForFile(ext3_file, std::string(), &ext_3_results);
125 IF_EXPECT_EQ(2U, ext_3_results.size()) { 121 ASSERT_EQ(2U, ext_3_results.size());
126 EXPECT_TRUE(VerifyApp1(ext_3_results, false)); 122 EXPECT_TRUE(VerifyApp1(ext_3_results, false));
127 EXPECT_TRUE(VerifyApp2(ext_3_results, true)); 123 EXPECT_TRUE(VerifyApp2(ext_3_results, true));
128 }
129 124
130 // Find by mimetype 'ext_3'. 125 // Find by mimetype 'ext_3'.
131 ScopedVector<DriveWebAppInfo> mime_results; 126 ScopedVector<DriveWebAppInfo> mime_results;
132 web_apps->GetWebAppsForFile(FilePath(), "application/test_type_2", 127 web_apps->GetWebAppsForFile(FilePath(), "application/test_type_2",
133 &mime_results); 128 &mime_results);
134 IF_EXPECT_EQ(1U, mime_results.size()) { 129 ASSERT_EQ(1U, mime_results.size());
135 EXPECT_TRUE(VerifyApp2(mime_results, true)); 130 EXPECT_TRUE(VerifyApp2(mime_results, true));
136 }
137 131
138 // Find by extension and mimetype. 132 // Find by extension and mimetype.
139 ScopedVector<DriveWebAppInfo> mime_ext_results; 133 ScopedVector<DriveWebAppInfo> mime_ext_results;
140 FilePath mime_file(FILE_PATH_LITERAL("gdata/MimeFile.ext_2")); 134 FilePath mime_file(FILE_PATH_LITERAL("gdata/MimeFile.ext_2"));
141 web_apps->GetWebAppsForFile(mime_file, "application/test_type_2", 135 web_apps->GetWebAppsForFile(mime_file, "application/test_type_2",
142 &mime_ext_results); 136 &mime_ext_results);
143 IF_EXPECT_EQ(2U, mime_ext_results.size()) { 137 ASSERT_EQ(2U, mime_ext_results.size());
144 EXPECT_TRUE(VerifyApp1(mime_ext_results, true)); 138 EXPECT_TRUE(VerifyApp1(mime_ext_results, true));
145 EXPECT_TRUE(VerifyApp2(mime_ext_results, true)); 139 EXPECT_TRUE(VerifyApp2(mime_ext_results, true));
146 } 140 }
141
142 TEST_F(DriveWebAppsRegistryTest, LoadAndFindDriveWebApps) {
143 scoped_ptr<Value> document(LoadJSONFile("drive", "applist.json"));
144 ASSERT_TRUE(document.get());
145 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY);
146
147 // Load feed.
148 scoped_ptr<AppList> app_list(AppList::CreateFrom(*document));
149 ASSERT_TRUE(app_list.get());
150 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry);
151 web_apps->UpdateFromApplicationList(*app_list.get());
152
153 // Find by primary extension 'exe'.
154 ScopedVector<DriveWebAppInfo> ext_results;
155 FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe"));
156 web_apps->GetWebAppsForFile(ext_file, std::string(), &ext_results);
157 ASSERT_EQ(1U, ext_results.size());
158 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
159 "Drive app 1", "", true);
160
161 // Find by primary MIME type.
162 ScopedVector<DriveWebAppInfo> primary_app;
163 web_apps->GetWebAppsForFile(FilePath(),
164 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app);
165 ASSERT_EQ(1U, primary_app.size());
166 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
167 "Drive app 1", "", true);
168
169 // Find by secondary MIME type.
170 ScopedVector<DriveWebAppInfo> secondary_app;
171 web_apps->GetWebAppsForFile(FilePath(), "text/html", &secondary_app);
172 ASSERT_EQ(1U, secondary_app.size());
173 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192",
174 "Drive app 1", "", false);
147 } 175 }
148 176
149 } // namespace gdata 177 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_webapps_registry.cc ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698