Chromium Code Reviews| 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 "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) | |
|
satorux1
2012/08/14 13:04:55
Glad to see this gone!
| |
| 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") |
| 42 .AppendASCII("gdata") | 40 .AppendASCII(prefix.c_str()) |
|
satorux1
2012/08/14 13:04:55
indentation is wrong? please remove .c_str()
kochi
2012/08/15 03:33:02
Done.
| |
| 43 .AppendASCII(filename.c_str()); | 41 .AppendASCII(filename.c_str()); |
|
satorux1
2012/08/14 13:04:55
remove c_str()
kochi
2012/08/15 03:33:02
Done.
| |
| 44 EXPECT_TRUE(file_util::PathExists(path)) << | 42 EXPECT_TRUE(file_util::PathExists(path)) << |
| 45 "Couldn't find " << path.value(); | 43 "Couldn't find " << path.value(); |
| 46 | 44 |
| 47 JSONFileValueSerializer serializer(path); | 45 JSONFileValueSerializer serializer(path); |
| 48 Value* value = serializer.Deserialize(NULL, &error); | 46 Value* value = serializer.Deserialize(NULL, &error); |
| 49 EXPECT_TRUE(value) << | 47 EXPECT_TRUE(value) << |
| 50 "Parse error " << path.value() << ": " << error; | 48 "Parse error " << path.value() << ": " << error; |
| 51 return value; | 49 return value; |
| 52 } | 50 } |
| 53 | 51 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 "Drive App 2", "Drive App Object 2", | 86 "Drive App 2", "Drive App Object 2", |
| 89 is_primary); | 87 is_primary); |
| 90 } | 88 } |
| 91 | 89 |
| 92 private: | 90 private: |
| 93 MessageLoopForUI message_loop_; | 91 MessageLoopForUI message_loop_; |
| 94 content::TestBrowserThread ui_thread_; | 92 content::TestBrowserThread ui_thread_; |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) { | 95 TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) { |
| 98 scoped_ptr<Value> document(LoadJSONFile("account_metadata.json")); | 96 scoped_ptr<Value> document(LoadJSONFile("gdata", "account_metadata.json")); |
| 99 ASSERT_TRUE(document.get()); | 97 ASSERT_TRUE(document.get()); |
| 100 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); | 98 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); |
| 101 DictionaryValue* entry_value; | 99 DictionaryValue* entry_value; |
| 102 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary( | 100 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary( |
| 103 std::string("entry"), &entry_value)); | 101 std::string("entry"), &entry_value)); |
| 104 ASSERT_TRUE(entry_value); | 102 ASSERT_TRUE(entry_value); |
| 105 | 103 |
| 106 // Load feed. | 104 // Load feed. |
| 107 scoped_ptr<AccountMetadataFeed> feed( | 105 scoped_ptr<AccountMetadataFeed> feed( |
| 108 AccountMetadataFeed::CreateFrom(*document)); | 106 AccountMetadataFeed::CreateFrom(*document)); |
| 109 ASSERT_TRUE(feed.get()); | 107 ASSERT_TRUE(feed.get()); |
| 110 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry); | 108 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry); |
| 111 web_apps->UpdateFromFeed(feed.get()); | 109 web_apps->UpdateFromFeed(*feed.get()); |
| 112 | 110 |
| 113 // Find by extension 'ext_1'. | 111 // Find by extension 'ext_1'. |
| 114 ScopedVector<DriveWebAppInfo> ext_1_results; | 112 ScopedVector<DriveWebAppInfo> ext_1_results; |
| 115 FilePath ext1_file(FILE_PATH_LITERAL("gdata/SampleFile.ext_1")); | 113 FilePath ext1_file(FILE_PATH_LITERAL("gdata/SampleFile.ext_1")); |
| 116 web_apps->GetWebAppsForFile(ext1_file, std::string(), &ext_1_results); | 114 web_apps->GetWebAppsForFile(ext1_file, std::string(), &ext_1_results); |
| 117 IF_EXPECT_EQ(1U, ext_1_results.size()) { | 115 ASSERT_EQ(1U, ext_1_results.size()); |
| 118 EXPECT_TRUE(VerifyApp1(ext_1_results, true)); | 116 EXPECT_TRUE(VerifyApp1(ext_1_results, true)); |
| 119 } | |
| 120 | 117 |
| 121 // Find by extension 'ext_3'. | 118 // Find by extension 'ext_3'. |
| 122 ScopedVector<DriveWebAppInfo> ext_3_results; | 119 ScopedVector<DriveWebAppInfo> ext_3_results; |
| 123 FilePath ext3_file(FILE_PATH_LITERAL("gdata/AnotherFile.ext_3")); | 120 FilePath ext3_file(FILE_PATH_LITERAL("gdata/AnotherFile.ext_3")); |
| 124 web_apps->GetWebAppsForFile(ext3_file, std::string(), &ext_3_results); | 121 web_apps->GetWebAppsForFile(ext3_file, std::string(), &ext_3_results); |
| 125 IF_EXPECT_EQ(2U, ext_3_results.size()) { | 122 ASSERT_EQ(2U, ext_3_results.size()); |
| 126 EXPECT_TRUE(VerifyApp1(ext_3_results, false)); | 123 EXPECT_TRUE(VerifyApp1(ext_3_results, false)); |
| 127 EXPECT_TRUE(VerifyApp2(ext_3_results, true)); | 124 EXPECT_TRUE(VerifyApp2(ext_3_results, true)); |
| 128 } | |
| 129 | 125 |
| 130 // Find by mimetype 'ext_3'. | 126 // Find by mimetype 'ext_3'. |
| 131 ScopedVector<DriveWebAppInfo> mime_results; | 127 ScopedVector<DriveWebAppInfo> mime_results; |
| 132 web_apps->GetWebAppsForFile(FilePath(), "application/test_type_2", | 128 web_apps->GetWebAppsForFile(FilePath(), "application/test_type_2", |
| 133 &mime_results); | 129 &mime_results); |
| 134 IF_EXPECT_EQ(1U, mime_results.size()) { | 130 ASSERT_EQ(1U, mime_results.size()); |
| 135 EXPECT_TRUE(VerifyApp2(mime_results, true)); | 131 EXPECT_TRUE(VerifyApp2(mime_results, true)); |
| 136 } | |
| 137 | 132 |
| 138 // Find by extension and mimetype. | 133 // Find by extension and mimetype. |
| 139 ScopedVector<DriveWebAppInfo> mime_ext_results; | 134 ScopedVector<DriveWebAppInfo> mime_ext_results; |
| 140 FilePath mime_file(FILE_PATH_LITERAL("gdata/MimeFile.ext_2")); | 135 FilePath mime_file(FILE_PATH_LITERAL("gdata/MimeFile.ext_2")); |
| 141 web_apps->GetWebAppsForFile(mime_file, "application/test_type_2", | 136 web_apps->GetWebAppsForFile(mime_file, "application/test_type_2", |
| 142 &mime_ext_results); | 137 &mime_ext_results); |
| 143 IF_EXPECT_EQ(2U, mime_ext_results.size()) { | 138 ASSERT_EQ(2U, mime_ext_results.size()); |
| 144 EXPECT_TRUE(VerifyApp1(mime_ext_results, true)); | 139 EXPECT_TRUE(VerifyApp1(mime_ext_results, true)); |
| 145 EXPECT_TRUE(VerifyApp2(mime_ext_results, true)); | 140 EXPECT_TRUE(VerifyApp2(mime_ext_results, true)); |
| 146 } | 141 } |
| 142 | |
| 143 TEST_F(DriveWebAppsRegistryTest, LoadAndFindDriveWebApps) { | |
| 144 scoped_ptr<Value> document(LoadJSONFile("drive", "applist.json")); | |
| 145 ASSERT_TRUE(document.get()); | |
| 146 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); | |
| 147 | |
| 148 // Load feed. | |
| 149 scoped_ptr<AppList> app_list(AppList::CreateFrom(*document)); | |
| 150 ASSERT_TRUE(app_list.get()); | |
| 151 scoped_ptr<DriveWebAppsRegistry> web_apps(new DriveWebAppsRegistry); | |
| 152 web_apps->UpdateFromApplicationList(*app_list.get()); | |
| 153 | |
| 154 // Find by primary extension 'exe'. | |
| 155 ScopedVector<DriveWebAppInfo> ext_results; | |
| 156 FilePath ext_file(FILE_PATH_LITERAL("drive/file.exe")); | |
| 157 web_apps->GetWebAppsForFile(ext_file, std::string(), &ext_results); | |
| 158 ASSERT_EQ(1U, ext_results.size()); | |
| 159 VerifyApp(ext_results, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", | |
| 160 "Drive app 1", "", true); | |
| 161 | |
| 162 // Find by primary MIME type. | |
| 163 ScopedVector<DriveWebAppInfo> primary_app; | |
| 164 web_apps->GetWebAppsForFile(FilePath(), | |
| 165 "application/vnd.google-apps.drive-sdk.123456788192", &primary_app); | |
| 166 ASSERT_EQ(1U, primary_app.size()); | |
| 167 VerifyApp(primary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", | |
| 168 "Drive app 1", "", true); | |
| 169 | |
| 170 // Find by secondary MIME type. | |
| 171 ScopedVector<DriveWebAppInfo> secondary_app; | |
| 172 web_apps->GetWebAppsForFile(FilePath(), "text/html", &secondary_app); | |
| 173 ASSERT_EQ(1U, secondary_app.size()); | |
| 174 VerifyApp(secondary_app, "abcdefghabcdefghabcdefghabcdefgh", "123456788192", | |
| 175 "Drive app 1", "", false); | |
| 147 } | 176 } |
| 148 | 177 |
| 149 } // namespace gdata | 178 } // namespace gdata |
| OLD | NEW |