| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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 // Browser test for basic Chrome OS file manager functionality: | |
| 6 // - The file list is updated when a file is added externally to the Downloads | |
| 7 // folder. | |
| 8 // - Selecting a file and copy-pasting it with the keyboard copies the file. | |
| 9 // - Selecting a file and pressing delete deletes it. | |
| 10 | |
| 11 #include <deque> | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/bind.h" | |
| 15 #include "base/callback.h" | |
| 16 #include "base/file_util.h" | |
| 17 #include "base/files/file_path.h" | |
| 18 #include "base/json/json_reader.h" | |
| 19 #include "base/json/json_value_converter.h" | |
| 20 #include "base/strings/string_piece.h" | |
| 21 #include "base/time/time.h" | |
| 22 #include "chrome/browser/chrome_notification_types.h" | |
| 23 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | |
| 24 #include "chrome/browser/chromeos/drive/file_system_interface.h" | |
| 25 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" | |
| 26 #include "chrome/browser/drive/fake_drive_service.h" | |
| 27 #include "chrome/browser/extensions/api/test/test_api.h" | |
| 28 #include "chrome/browser/extensions/component_loader.h" | |
| 29 #include "chrome/browser/extensions/extension_apitest.h" | |
| 30 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
| 31 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | |
| 32 #include "chrome/browser/google_apis/test_util.h" | |
| 33 #include "chrome/browser/profiles/profile.h" | |
| 34 #include "chrome/common/chrome_switches.h" | |
| 35 #include "chrome/common/extensions/extension.h" | |
| 36 #include "chromeos/chromeos_switches.h" | |
| 37 #include "content/public/browser/browser_context.h" | |
| 38 #include "content/public/browser/notification_service.h" | |
| 39 #include "content/public/test/test_utils.h" | |
| 40 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 41 #include "webkit/browser/fileapi/external_mount_points.h" | |
| 42 | |
| 43 namespace file_manager { | |
| 44 namespace { | |
| 45 | |
| 46 enum EntryType { | |
| 47 FILE, | |
| 48 DIRECTORY, | |
| 49 }; | |
| 50 | |
| 51 enum TargetVolume { | |
| 52 LOCAL_VOLUME, | |
| 53 DRIVE_VOLUME, | |
| 54 }; | |
| 55 | |
| 56 enum SharedOption { | |
| 57 NONE, | |
| 58 SHARED, | |
| 59 }; | |
| 60 | |
| 61 enum GuestMode { | |
| 62 NOT_IN_GUEST_MODE, | |
| 63 IN_GUEST_MODE, | |
| 64 }; | |
| 65 | |
| 66 // This global operator is used from Google Test to format error messages. | |
| 67 std::ostream& operator<<(std::ostream& os, const GuestMode& guest_mode) { | |
| 68 return os << (guest_mode == IN_GUEST_MODE ? | |
| 69 "IN_GUEST_MODE" : "NOT_IN_GUEST_MODE"); | |
| 70 } | |
| 71 | |
| 72 // Maps the given string to EntryType. Returns true on success. | |
| 73 bool MapStringToEntryType(const base::StringPiece& value, EntryType* output) { | |
| 74 if (value == "file") | |
| 75 *output = FILE; | |
| 76 else if (value == "directory") | |
| 77 *output = DIRECTORY; | |
| 78 else | |
| 79 return false; | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 // Maps the given string to SharedOption. Returns true on success. | |
| 84 bool MapStringToSharedOption(const base::StringPiece& value, | |
| 85 SharedOption* output) { | |
| 86 if (value == "shared") | |
| 87 *output = SHARED; | |
| 88 else if (value == "none") | |
| 89 *output = NONE; | |
| 90 else | |
| 91 return false; | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 // Maps the given string to TargetVolume. Returns true on success. | |
| 96 bool MapStringToTargetVolume(const base::StringPiece& value, | |
| 97 TargetVolume* output) { | |
| 98 if (value == "drive") | |
| 99 *output = DRIVE_VOLUME; | |
| 100 else if (value == "local") | |
| 101 *output = LOCAL_VOLUME; | |
| 102 else | |
| 103 return false; | |
| 104 return true; | |
| 105 } | |
| 106 | |
| 107 // Maps the given string to base::Time. Returns true on success. | |
| 108 bool MapStringToTime(const base::StringPiece& value, base::Time* time) { | |
| 109 return base::Time::FromString(value.as_string().c_str(), time); | |
| 110 } | |
| 111 | |
| 112 // Test data of file or directory. | |
| 113 struct TestEntryInfo { | |
| 114 TestEntryInfo() : type(FILE), shared_option(NONE) {} | |
| 115 | |
| 116 TestEntryInfo(EntryType type, | |
| 117 const std::string& source_file_name, | |
| 118 const std::string& target_name, | |
| 119 const std::string& mime_type, | |
| 120 SharedOption shared_option, | |
| 121 const base::Time& last_modified_time) : | |
| 122 type(type), | |
| 123 source_file_name(source_file_name), | |
| 124 target_name(target_name), | |
| 125 mime_type(mime_type), | |
| 126 shared_option(shared_option), | |
| 127 last_modified_time(last_modified_time) { | |
| 128 } | |
| 129 | |
| 130 EntryType type; | |
| 131 std::string source_file_name; // Source file name to be used as a prototype. | |
| 132 std::string target_name; // Target file or directory name. | |
| 133 std::string mime_type; | |
| 134 SharedOption shared_option; | |
| 135 base::Time last_modified_time; | |
| 136 | |
| 137 // Registers the member information to the given converter. | |
| 138 static void RegisterJSONConverter( | |
| 139 base::JSONValueConverter<TestEntryInfo>* converter); | |
| 140 }; | |
| 141 | |
| 142 // static | |
| 143 void TestEntryInfo::RegisterJSONConverter( | |
| 144 base::JSONValueConverter<TestEntryInfo>* converter) { | |
| 145 converter->RegisterCustomField("type", | |
| 146 &TestEntryInfo::type, | |
| 147 &MapStringToEntryType); | |
| 148 converter->RegisterStringField("source_file_name", | |
| 149 &TestEntryInfo::source_file_name); | |
| 150 converter->RegisterStringField("target_name", &TestEntryInfo::target_name); | |
| 151 converter->RegisterStringField("mime_type", &TestEntryInfo::mime_type); | |
| 152 converter->RegisterCustomField("shared_option", | |
| 153 &TestEntryInfo::shared_option, | |
| 154 &MapStringToSharedOption); | |
| 155 converter->RegisterCustomField("last_modified_time", | |
| 156 &TestEntryInfo::last_modified_time, | |
| 157 &MapStringToTime); | |
| 158 } | |
| 159 | |
| 160 // Message from JavaScript to add entries. | |
| 161 struct AddEntriesMessage { | |
| 162 // Target volume to be added the |entries|. | |
| 163 TargetVolume volume; | |
| 164 | |
| 165 // Entries to be added. | |
| 166 ScopedVector<TestEntryInfo> entries; | |
| 167 | |
| 168 // Registers the member information to the given converter. | |
| 169 static void RegisterJSONConverter( | |
| 170 base::JSONValueConverter<AddEntriesMessage>* converter); | |
| 171 }; | |
| 172 | |
| 173 | |
| 174 // static | |
| 175 void AddEntriesMessage::RegisterJSONConverter( | |
| 176 base::JSONValueConverter<AddEntriesMessage>* converter) { | |
| 177 converter->RegisterCustomField("volume", | |
| 178 &AddEntriesMessage::volume, | |
| 179 &MapStringToTargetVolume); | |
| 180 converter->RegisterRepeatedMessage<TestEntryInfo>( | |
| 181 "entries", | |
| 182 &AddEntriesMessage::entries); | |
| 183 } | |
| 184 | |
| 185 // Create the test entry data for common use. | |
| 186 std::vector<TestEntryInfo> createTestEntrySetCommon() { | |
| 187 std::vector<TestEntryInfo> entryInfoSet; | |
| 188 base::Time time; | |
| 189 base::Time::FromString("4 Sep 1998 12:34:56", &time); | |
| 190 entryInfoSet.push_back(TestEntryInfo( | |
| 191 FILE, "text.txt", "hello.txt", "text/plain", NONE, time)); | |
| 192 base::Time::FromString("18 Jan 2038 01:02:03", &time); | |
| 193 entryInfoSet.push_back(TestEntryInfo( | |
| 194 FILE, "image.png", "My Desktop Background.png", "text/plain", NONE, | |
| 195 time)); | |
| 196 base::Time::FromString("12 Nov 2086 12:00:00", &time); | |
| 197 entryInfoSet.push_back(TestEntryInfo( | |
| 198 FILE, "music.ogg", "Beautiful Song.ogg", "text/plain", NONE, time)); | |
| 199 base::Time::FromString("4 July 2012 10:35:00", &time); | |
| 200 entryInfoSet.push_back(TestEntryInfo( | |
| 201 FILE, "video.ogv", "world.ogv", "text/plain", NONE, time)); | |
| 202 base::Time::FromString("1 Jan 1980 23:59:59", &time); | |
| 203 entryInfoSet.push_back(TestEntryInfo( | |
| 204 DIRECTORY, "", "photos", "", NONE, time)); | |
| 205 base::Time::FromString("26 Oct 1985 13:39", &time); | |
| 206 entryInfoSet.push_back(TestEntryInfo( | |
| 207 DIRECTORY, "", ".warez", "", NONE, time)); | |
| 208 return entryInfoSet; | |
| 209 } | |
| 210 | |
| 211 // Creates the test entry data for the drive volume. | |
| 212 std::vector<TestEntryInfo> createTestEntrySetDriveOnly() { | |
| 213 std::vector<TestEntryInfo> entryInfoSet; | |
| 214 base::Time time; | |
| 215 base::Time::FromString("10 Apr 2013 16:20:00", &time); | |
| 216 entryInfoSet.push_back(TestEntryInfo( | |
| 217 FILE, "", "Test Document", "application/vnd.google-apps.document", NONE, | |
| 218 time)); | |
| 219 base::Time::FromString("20 Mar 2013 22:40:00", &time); | |
| 220 entryInfoSet.push_back(TestEntryInfo( | |
| 221 FILE, "", "Test Shared Document", "application/vnd.google-apps.document", | |
| 222 SHARED, time)); | |
| 223 return entryInfoSet; | |
| 224 } | |
| 225 | |
| 226 // The local volume class for test. | |
| 227 // This class provides the operations for a test volume that simulates local | |
| 228 // drive. | |
| 229 class LocalTestVolume { | |
| 230 public: | |
| 231 // Adds this volume to the file system as a local volume. Returns true on | |
| 232 // success. | |
| 233 bool Mount(Profile* profile) { | |
| 234 const std::string kDownloads = "Downloads"; | |
| 235 | |
| 236 if (local_path_.empty()) { | |
| 237 if (!tmp_dir_.CreateUniqueTempDir()) | |
| 238 return false; | |
| 239 local_path_ = tmp_dir_.path().Append(kDownloads); | |
| 240 } | |
| 241 fileapi::ExternalMountPoints* const mount_points = | |
| 242 content::BrowserContext::GetMountPoints(profile); | |
| 243 mount_points->RevokeFileSystem(kDownloads); | |
| 244 | |
| 245 return mount_points->RegisterFileSystem( | |
| 246 kDownloads, fileapi::kFileSystemTypeNativeLocal, local_path_) && | |
| 247 file_util::CreateDirectory(local_path_); | |
| 248 } | |
| 249 | |
| 250 void CreateEntry(const TestEntryInfo& entry) { | |
| 251 base::FilePath target_path = local_path_.AppendASCII(entry.target_name); | |
| 252 switch (entry.type) { | |
| 253 case FILE: { | |
| 254 base::FilePath source_path = | |
| 255 google_apis::test_util::GetTestFilePath("chromeos/file_manager"). | |
| 256 AppendASCII(entry.source_file_name); | |
| 257 ASSERT_TRUE(base::CopyFile(source_path, target_path)) | |
| 258 << "Copy from " << source_path.value() | |
| 259 << " to " << target_path.value() << " failed."; | |
| 260 break; | |
| 261 } | |
| 262 case DIRECTORY: | |
| 263 ASSERT_TRUE(file_util::CreateDirectory(target_path)) << | |
| 264 "Failed to create a directory: " << target_path.value(); | |
| 265 break; | |
| 266 } | |
| 267 ASSERT_TRUE( | |
| 268 file_util::SetLastModifiedTime(target_path, entry.last_modified_time)); | |
| 269 } | |
| 270 | |
| 271 private: | |
| 272 base::FilePath local_path_; | |
| 273 base::ScopedTempDir tmp_dir_; | |
| 274 }; | |
| 275 | |
| 276 // The drive volume class for test. | |
| 277 // This class provides the operations for a test volume that simulates Google | |
| 278 // drive. | |
| 279 class DriveTestVolume { | |
| 280 public: | |
| 281 DriveTestVolume() : fake_drive_service_(NULL), | |
| 282 integration_service_(NULL) { | |
| 283 } | |
| 284 | |
| 285 // Sends request to add this volume to the file system as Google drive. | |
| 286 // This method must be calld at SetUp method of FileManagerBrowserTestBase. | |
| 287 // Returns true on success. | |
| 288 bool SetUp() { | |
| 289 if (!test_cache_root_.CreateUniqueTempDir()) | |
| 290 return false; | |
| 291 drive::DriveIntegrationServiceFactory::SetFactoryForTest( | |
| 292 base::Bind(&DriveTestVolume::CreateDriveIntegrationService, | |
| 293 base::Unretained(this))); | |
| 294 return true; | |
| 295 } | |
| 296 | |
| 297 void CreateEntry(const TestEntryInfo& entry) { | |
| 298 switch (entry.type) { | |
| 299 case FILE: | |
| 300 CreateFile(entry.source_file_name, | |
| 301 entry.target_name, | |
| 302 entry.mime_type, | |
| 303 entry.shared_option == SHARED, | |
| 304 entry.last_modified_time); | |
| 305 break; | |
| 306 case DIRECTORY: | |
| 307 CreateDirectory(entry.target_name, entry.last_modified_time); | |
| 308 break; | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 // Creates an empty directory with the given |name| and |modification_time|. | |
| 313 void CreateDirectory(const std::string& name, | |
| 314 const base::Time& modification_time) { | |
| 315 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | |
| 316 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
| 317 fake_drive_service_->AddNewDirectory( | |
| 318 fake_drive_service_->GetRootResourceId(), | |
| 319 name, | |
| 320 google_apis::test_util::CreateCopyResultCallback(&error, | |
| 321 &resource_entry)); | |
| 322 base::MessageLoop::current()->RunUntilIdle(); | |
| 323 ASSERT_TRUE(error == google_apis::HTTP_CREATED); | |
| 324 ASSERT_TRUE(resource_entry); | |
| 325 | |
| 326 fake_drive_service_->SetLastModifiedTime( | |
| 327 resource_entry->resource_id(), | |
| 328 modification_time, | |
| 329 google_apis::test_util::CreateCopyResultCallback(&error, | |
| 330 &resource_entry)); | |
| 331 base::MessageLoop::current()->RunUntilIdle(); | |
| 332 ASSERT_TRUE(error == google_apis::HTTP_SUCCESS); | |
| 333 ASSERT_TRUE(resource_entry); | |
| 334 CheckForUpdates(); | |
| 335 } | |
| 336 | |
| 337 // Creates a test file with the given spec. | |
| 338 // Serves |test_file_name| file. Pass an empty string for an empty file. | |
| 339 void CreateFile(const std::string& source_file_name, | |
| 340 const std::string& target_file_name, | |
| 341 const std::string& mime_type, | |
| 342 bool shared_with_me, | |
| 343 const base::Time& modification_time) { | |
| 344 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | |
| 345 | |
| 346 std::string content_data; | |
| 347 if (!source_file_name.empty()) { | |
| 348 base::FilePath source_file_path = | |
| 349 google_apis::test_util::GetTestFilePath("chromeos/file_manager"). | |
| 350 AppendASCII(source_file_name); | |
| 351 ASSERT_TRUE(base::ReadFileToString(source_file_path, &content_data)); | |
| 352 } | |
| 353 | |
| 354 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
| 355 fake_drive_service_->AddNewFile( | |
| 356 mime_type, | |
| 357 content_data, | |
| 358 fake_drive_service_->GetRootResourceId(), | |
| 359 target_file_name, | |
| 360 shared_with_me, | |
| 361 google_apis::test_util::CreateCopyResultCallback(&error, | |
| 362 &resource_entry)); | |
| 363 base::MessageLoop::current()->RunUntilIdle(); | |
| 364 ASSERT_EQ(google_apis::HTTP_CREATED, error); | |
| 365 ASSERT_TRUE(resource_entry); | |
| 366 | |
| 367 fake_drive_service_->SetLastModifiedTime( | |
| 368 resource_entry->resource_id(), | |
| 369 modification_time, | |
| 370 google_apis::test_util::CreateCopyResultCallback(&error, | |
| 371 &resource_entry)); | |
| 372 base::MessageLoop::current()->RunUntilIdle(); | |
| 373 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | |
| 374 ASSERT_TRUE(resource_entry); | |
| 375 | |
| 376 CheckForUpdates(); | |
| 377 } | |
| 378 | |
| 379 // Notifies FileSystem that the contents in FakeDriveService are | |
| 380 // changed, hence the new contents should be fetched. | |
| 381 void CheckForUpdates() { | |
| 382 if (integration_service_ && integration_service_->file_system()) { | |
| 383 integration_service_->file_system()->CheckForUpdates(); | |
| 384 } | |
| 385 } | |
| 386 | |
| 387 // Sets the url base for the test server to be used to generate share urls | |
| 388 // on the files and directories. | |
| 389 void ConfigureShareUrlBase(const GURL& share_url_base) { | |
| 390 fake_drive_service_->set_share_url_base(share_url_base); | |
| 391 } | |
| 392 | |
| 393 drive::DriveIntegrationService* CreateDriveIntegrationService( | |
| 394 Profile* profile) { | |
| 395 fake_drive_service_ = new drive::FakeDriveService; | |
| 396 fake_drive_service_->LoadResourceListForWapi( | |
| 397 "gdata/empty_feed.json"); | |
| 398 fake_drive_service_->LoadAccountMetadataForWapi( | |
| 399 "gdata/account_metadata.json"); | |
| 400 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | |
| 401 integration_service_ = new drive::DriveIntegrationService( | |
| 402 profile, | |
| 403 fake_drive_service_, | |
| 404 test_cache_root_.path(), | |
| 405 NULL); | |
| 406 return integration_service_; | |
| 407 } | |
| 408 | |
| 409 private: | |
| 410 base::ScopedTempDir test_cache_root_; | |
| 411 drive::FakeDriveService* fake_drive_service_; | |
| 412 drive::DriveIntegrationService* integration_service_; | |
| 413 }; | |
| 414 | |
| 415 // Listener to obtain the test relative messages synchronously. | |
| 416 class FileManagerTestListener : public content::NotificationObserver { | |
| 417 public: | |
| 418 struct Message { | |
| 419 int type; | |
| 420 std::string message; | |
| 421 extensions::TestSendMessageFunction* function; | |
| 422 }; | |
| 423 | |
| 424 FileManagerTestListener() { | |
| 425 registrar_.Add(this, | |
| 426 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, | |
| 427 content::NotificationService::AllSources()); | |
| 428 registrar_.Add(this, | |
| 429 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, | |
| 430 content::NotificationService::AllSources()); | |
| 431 registrar_.Add(this, | |
| 432 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | |
| 433 content::NotificationService::AllSources()); | |
| 434 } | |
| 435 | |
| 436 Message GetNextMessage() { | |
| 437 if (messages_.empty()) | |
| 438 content::RunMessageLoop(); | |
| 439 const Message entry = messages_.front(); | |
| 440 messages_.pop_front(); | |
| 441 return entry; | |
| 442 } | |
| 443 | |
| 444 virtual void Observe(int type, | |
| 445 const content::NotificationSource& source, | |
| 446 const content::NotificationDetails& details) OVERRIDE { | |
| 447 Message entry; | |
| 448 entry.type = type; | |
| 449 entry.message = type != chrome::NOTIFICATION_EXTENSION_TEST_PASSED ? | |
| 450 *content::Details<std::string>(details).ptr() : | |
| 451 std::string(); | |
| 452 entry.function = type == chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE ? | |
| 453 content::Source<extensions::TestSendMessageFunction>(source).ptr() : | |
| 454 NULL; | |
| 455 messages_.push_back(entry); | |
| 456 base::MessageLoopForUI::current()->Quit(); | |
| 457 } | |
| 458 | |
| 459 private: | |
| 460 std::deque<Message> messages_; | |
| 461 content::NotificationRegistrar registrar_; | |
| 462 }; | |
| 463 | |
| 464 // Parameter of FileManagerBrowserTest. | |
| 465 // The second value is the case name of JavaScript. | |
| 466 typedef std::tr1::tuple<GuestMode, const char*> TestParameter; | |
| 467 | |
| 468 // The base test class. | |
| 469 class FileManagerBrowserTest : | |
| 470 public ExtensionApiTest, | |
| 471 public ::testing::WithParamInterface<TestParameter> { | |
| 472 protected: | |
| 473 FileManagerBrowserTest() : | |
| 474 local_volume_(new LocalTestVolume), | |
| 475 drive_volume_(std::tr1::get<0>(GetParam()) != IN_GUEST_MODE ? | |
| 476 new DriveTestVolume() : NULL) {} | |
| 477 | |
| 478 virtual void SetUp() OVERRIDE { | |
| 479 // TODO(danakj): The GPU Video Decoder needs real GL bindings. | |
| 480 // crbug.com/269087 | |
| 481 UseRealGLBindings(); | |
| 482 | |
| 483 ExtensionApiTest::SetUp(); | |
| 484 } | |
| 485 | |
| 486 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | |
| 487 | |
| 488 virtual void SetUpOnMainThread() OVERRIDE; | |
| 489 | |
| 490 // Adds an incognito and guest-mode flags for tests in the guest mode. | |
| 491 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | |
| 492 | |
| 493 // Loads our testing extension and sends it a string identifying the current | |
| 494 // test. | |
| 495 void StartTest(); | |
| 496 | |
| 497 const scoped_ptr<LocalTestVolume> local_volume_; | |
| 498 const scoped_ptr<DriveTestVolume> drive_volume_; | |
| 499 }; | |
| 500 | |
| 501 void FileManagerBrowserTest::SetUpInProcessBrowserTestFixture() { | |
| 502 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 503 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); | |
| 504 if (drive_volume_) | |
| 505 ASSERT_TRUE(drive_volume_->SetUp()); | |
| 506 } | |
| 507 | |
| 508 void FileManagerBrowserTest::SetUpOnMainThread() { | |
| 509 ExtensionApiTest::SetUpOnMainThread(); | |
| 510 ASSERT_TRUE(local_volume_->Mount(browser()->profile())); | |
| 511 | |
| 512 const std::vector<TestEntryInfo> testEntrySetCommon( | |
| 513 createTestEntrySetCommon()); | |
| 514 const std::vector<TestEntryInfo> testEntrySetDriveOnly( | |
| 515 createTestEntrySetDriveOnly()); | |
| 516 | |
| 517 for (size_t i = 0; i < testEntrySetCommon.size(); ++i) | |
| 518 local_volume_->CreateEntry(testEntrySetCommon[i]); | |
| 519 | |
| 520 if (drive_volume_) { | |
| 521 // Install the web server to serve the mocked share dialog. | |
| 522 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 523 const GURL share_url_base(embedded_test_server()->GetURL( | |
| 524 "/chromeos/file_manager/share_dialog_mock/index.html")); | |
| 525 drive_volume_->ConfigureShareUrlBase(share_url_base); | |
| 526 | |
| 527 for (size_t i = 0; i < testEntrySetCommon.size(); ++i) | |
| 528 drive_volume_->CreateEntry(testEntrySetCommon[i]); | |
| 529 | |
| 530 // For testing Drive, create more entries with Drive specific attributes. | |
| 531 // TODO(haruki): Add a case for an entry cached by DriveCache. | |
| 532 for (size_t i = 0; i < testEntrySetDriveOnly.size(); ++i) | |
| 533 drive_volume_->CreateEntry(testEntrySetDriveOnly[i]); | |
| 534 | |
| 535 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); | |
| 536 } | |
| 537 } | |
| 538 | |
| 539 void FileManagerBrowserTest::SetUpCommandLine(CommandLine* command_line) { | |
| 540 if (std::tr1::get<0>(GetParam()) == IN_GUEST_MODE) { | |
| 541 command_line->AppendSwitch(chromeos::switches::kGuestSession); | |
| 542 command_line->AppendSwitchNative(chromeos::switches::kLoginUser, ""); | |
| 543 command_line->AppendSwitch(switches::kIncognito); | |
| 544 } | |
| 545 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 546 } | |
| 547 | |
| 548 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) { | |
| 549 // Launch the extension. | |
| 550 base::FilePath path = test_data_dir_.AppendASCII("file_manager_browsertest"); | |
| 551 const extensions::Extension* extension = LoadExtensionAsComponent(path); | |
| 552 ASSERT_TRUE(extension); | |
| 553 | |
| 554 // Handle the messages from JavaScript. | |
| 555 // The while loop is break when the test is passed or failed. | |
| 556 FileManagerTestListener listener; | |
| 557 base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter; | |
| 558 while (true) { | |
| 559 FileManagerTestListener::Message entry = listener.GetNextMessage(); | |
| 560 if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_PASSED) { | |
| 561 // Test succeed. | |
| 562 break; | |
| 563 } else if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_FAILED) { | |
| 564 // Test failed. | |
| 565 ADD_FAILURE() << entry.message; | |
| 566 break; | |
| 567 } | |
| 568 | |
| 569 // Parse the message value as JSON. | |
| 570 const scoped_ptr<const base::Value> value( | |
| 571 base::JSONReader::Read(entry.message)); | |
| 572 | |
| 573 // If the message is not the expected format, just ignore it. | |
| 574 const base::DictionaryValue* message_dictionary = NULL; | |
| 575 std::string name; | |
| 576 if (!value || !value->GetAsDictionary(&message_dictionary) || | |
| 577 !message_dictionary->GetString("name", &name)) | |
| 578 continue; | |
| 579 | |
| 580 if (name == "getTestName") { | |
| 581 // Pass the test case name. | |
| 582 entry.function->Reply(std::tr1::get<1>(GetParam())); | |
| 583 } else if (name == "isInGuestMode") { | |
| 584 // Obtain whether the test is in guest mode or not. | |
| 585 entry.function->Reply(std::tr1::get<0>(GetParam()) ? "true" : "false"); | |
| 586 } else if (name == "addEntries") { | |
| 587 // Add entries to the specified volume. | |
| 588 AddEntriesMessage message; | |
| 589 if (!add_entries_message_converter.Convert(*value.get(), &message)) { | |
| 590 entry.function->Reply("onError"); | |
| 591 continue; | |
| 592 } | |
| 593 for (size_t i = 0; i < message.entries.size(); ++i) { | |
| 594 switch (message.volume) { | |
| 595 case LOCAL_VOLUME: | |
| 596 local_volume_->CreateEntry(*message.entries[i]); | |
| 597 break; | |
| 598 case DRIVE_VOLUME: | |
| 599 if (drive_volume_) | |
| 600 drive_volume_->CreateEntry(*message.entries[i]); | |
| 601 break; | |
| 602 default: | |
| 603 NOTREACHED(); | |
| 604 break; | |
| 605 } | |
| 606 } | |
| 607 entry.function->Reply("onEntryAdded"); | |
| 608 } | |
| 609 } | |
| 610 } | |
| 611 | |
| 612 INSTANTIATE_TEST_CASE_P( | |
| 613 FileDisplay, | |
| 614 FileManagerBrowserTest, | |
| 615 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDownloads"), | |
| 616 TestParameter(IN_GUEST_MODE, "fileDisplayDownloads"), | |
| 617 TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDrive"))); | |
| 618 | |
| 619 // TODO(mtomasz): Fix this test. crbug.com/252561 | |
| 620 /* | |
| 621 INSTANTIATE_TEST_CASE_P( | |
| 622 OpenSpecialTypes, | |
| 623 FileManagerBrowserTest, | |
| 624 ::testing::Values(TestParameter(IN_GUEST_MODE, "videoOpenDownloads"), | |
| 625 TestParameter(NOT_IN_GUEST_MODE, "videoOpenDownloads"), | |
| 626 TestParameter(NOT_IN_GUEST_MODE, "videoOpenDrive"), | |
| 627 TestParameter(IN_GUEST_MODE, "audioOpenDownloads"), | |
| 628 TestParameter(NOT_IN_GUEST_MODE, "audioOpenDownloads"), | |
| 629 TestParameter(NOT_IN_GUEST_MODE, "audioOpenDrive"), | |
| 630 TestParameter(IN_GUEST_MODE, "galleryOpenDownloads"), | |
| 631 TestParameter(NOT_IN_GUEST_MODE, | |
| 632 "galleryOpenDownloads"), | |
| 633 TestParameter(NOT_IN_GUEST_MODE, "galleryOpenDrive"))); | |
| 634 */ | |
| 635 | |
| 636 INSTANTIATE_TEST_CASE_P( | |
| 637 KeyboardOperations, | |
| 638 FileManagerBrowserTest, | |
| 639 ::testing::Values(TestParameter(IN_GUEST_MODE, "keyboardDeleteDownloads"), | |
| 640 TestParameter(NOT_IN_GUEST_MODE, | |
| 641 "keyboardDeleteDownloads"), | |
| 642 TestParameter(NOT_IN_GUEST_MODE, "keyboardDeleteDrive"), | |
| 643 TestParameter(IN_GUEST_MODE, "keyboardCopyDownloads"), | |
| 644 TestParameter(NOT_IN_GUEST_MODE, "keyboardCopyDownloads"), | |
| 645 TestParameter(NOT_IN_GUEST_MODE, "keyboardCopyDrive"))); | |
| 646 | |
| 647 INSTANTIATE_TEST_CASE_P( | |
| 648 DriveSpecific, | |
| 649 FileManagerBrowserTest, | |
| 650 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "openSidebarRecent"), | |
| 651 TestParameter(NOT_IN_GUEST_MODE, "openSidebarOffline"), | |
| 652 TestParameter(NOT_IN_GUEST_MODE, | |
| 653 "openSidebarSharedWithMe"), | |
| 654 TestParameter(NOT_IN_GUEST_MODE, "autocomplete"))); | |
| 655 | |
| 656 INSTANTIATE_TEST_CASE_P( | |
| 657 Transfer, | |
| 658 FileManagerBrowserTest, | |
| 659 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, | |
| 660 "transferFromDriveToDownloads"), | |
| 661 TestParameter(NOT_IN_GUEST_MODE, | |
| 662 "transferFromDownloadsToDrive"), | |
| 663 TestParameter(NOT_IN_GUEST_MODE, | |
| 664 "transferFromSharedToDownloads"), | |
| 665 TestParameter(NOT_IN_GUEST_MODE, | |
| 666 "transferFromSharedToDrive"), | |
| 667 TestParameter(NOT_IN_GUEST_MODE, | |
| 668 "transferFromRecentToDownloads"), | |
| 669 TestParameter(NOT_IN_GUEST_MODE, | |
| 670 "transferFromRecentToDrive"), | |
| 671 TestParameter(NOT_IN_GUEST_MODE, | |
| 672 "transferFromOfflineToDownloads"), | |
| 673 TestParameter(NOT_IN_GUEST_MODE, | |
| 674 "transferFromOfflineToDrive"))); | |
| 675 | |
| 676 INSTANTIATE_TEST_CASE_P( | |
| 677 HideSearchBox, | |
| 678 FileManagerBrowserTest, | |
| 679 ::testing::Values(TestParameter(IN_GUEST_MODE, "hideSearchBox"), | |
| 680 TestParameter(NOT_IN_GUEST_MODE, "hideSearchBox"))); | |
| 681 | |
| 682 INSTANTIATE_TEST_CASE_P( | |
| 683 RestorePrefs, | |
| 684 FileManagerBrowserTest, | |
| 685 ::testing::Values(TestParameter(IN_GUEST_MODE, "restoreSortColumn"), | |
| 686 TestParameter(NOT_IN_GUEST_MODE, "restoreSortColumn"), | |
| 687 TestParameter(IN_GUEST_MODE, "restoreCurrentView"), | |
| 688 TestParameter(NOT_IN_GUEST_MODE, "restoreCurrentView"))); | |
| 689 | |
| 690 INSTANTIATE_TEST_CASE_P( | |
| 691 ShareDialog, | |
| 692 FileManagerBrowserTest, | |
| 693 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "shareFile"), | |
| 694 TestParameter(NOT_IN_GUEST_MODE, "shareDirectory"))); | |
| 695 | |
| 696 INSTANTIATE_TEST_CASE_P( | |
| 697 restoreGeometry, | |
| 698 FileManagerBrowserTest, | |
| 699 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "restoreGeometry"), | |
| 700 TestParameter(IN_GUEST_MODE, "restoreGeometry"))); | |
| 701 | |
| 702 } // namespace | |
| 703 } // namespace file_manager | |
| OLD | NEW |