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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc

Issue 137463006: Add tests for Google Drive integration in chrome.fileSystem API on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. Created 6 years, 11 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
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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/apps/app_browsertest_util.h"
6 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
7 #include "chrome/browser/chromeos/drive/file_system_interface.h"
8 #include "chrome/browser/chromeos/drive/file_system_util.h"
9 #include "chrome/browser/chromeos/drive/test_util.h"
10 #include "chrome/browser/drive/fake_drive_service.h"
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
12 #include "content/public/test/test_utils.h"
13 #include "google_apis/drive/test_util.h"
14
15 namespace extensions {
16
17 // This class contains chrome.filesystem API test specific to Chrome OS, namely,
18 // the integrated Google Drive support.
19 class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
20 public:
21 FileSystemApiTestForDrive()
22 : fake_drive_service_(NULL),
23 integration_service_(NULL) {
24 }
25
26 // Sets up fake Drive service for tests (this has to be injected before the
27 // real DriveIntegrationService instance is created.)
28 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
29 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
30
31 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir());
32
33 create_drive_integration_service_ =
34 base::Bind(&FileSystemApiTestForDrive::CreateDriveIntegrationService,
35 base::Unretained(this));
36 service_factory_for_test_.reset(
37 new drive::DriveIntegrationServiceFactory::ScopedFactoryForTest(
38 &create_drive_integration_service_));
39 }
40
41 // Ensure the fake service's data is fetch in the local file system. This is
42 // necessary because the fetch starts lazily upon the first read operation.
43 virtual void SetUpOnMainThread() OVERRIDE {
44 PlatformAppBrowserTest::SetUpOnMainThread();
45
46 scoped_ptr<drive::ResourceEntry> entry;
47 drive::FileError error = drive::FILE_ERROR_FAILED;
48 integration_service_->file_system()->GetResourceEntry(
49 base::FilePath::FromUTF8Unsafe("drive/root"), // whatever
50 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
51 drive::test_util::RunBlockingPoolTask();
52 ASSERT_EQ(drive::FILE_ERROR_OK, error);
53 }
54
55 virtual void TearDown() OVERRIDE {
56 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
57 PlatformAppBrowserTest::TearDown();
58 };
59
60 private:
61 drive::DriveIntegrationService* CreateDriveIntegrationService(
62 Profile* profile) {
63 fake_drive_service_ = new drive::FakeDriveService;
64 fake_drive_service_->LoadResourceListForWapi(
65 "gdata/empty_feed.json");
66 fake_drive_service_->LoadAccountMetadataForWapi(
67 "gdata/account_metadata.json");
68 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
69
70 SetUpTestFileHierarchy();
71
72 integration_service_ = new drive::DriveIntegrationService(
73 profile, NULL, fake_drive_service_, test_cache_root_.path(), NULL);
74 return integration_service_;
75 }
76
77 void SetUpTestFileHierarchy() {
78 const std::string root = fake_drive_service_->GetRootResourceId();
79 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root));
80 }
81
82 bool AddTestFile(const std::string& title,
83 const std::string& data,
84 const std::string& parent_id) {
85 scoped_ptr<google_apis::ResourceEntry> resource_entry;
86 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
87 fake_drive_service_->AddNewFile(
88 "text/plain", data, parent_id, title, false,
89 google_apis::test_util::CreateCopyResultCallback(&error,
90 &resource_entry));
91 content::RunAllPendingInMessageLoop();
92 return error == google_apis::HTTP_CREATED && resource_entry;
93 }
94
95 base::ScopedTempDir test_cache_root_;
96 drive::FakeDriveService* fake_drive_service_;
97 drive::DriveIntegrationService* integration_service_;
98 drive::DriveIntegrationServiceFactory::FactoryCallback
99 create_drive_integration_service_;
100 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest>
101 service_factory_for_test_;
102 };
103
104 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
105 FileSystemApiOpenExistingFileTest) {
106 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII(
107 "root/open_existing.txt");
108 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
109 &test_file);
110 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
111 << message_;
112 }
113
114 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
115 FileSystemApiOpenExistingFileWithWriteTest) {
116 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII(
117 "root/open_existing.txt");
118 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
119 &test_file);
120 ASSERT_TRUE(RunPlatformAppTest(
121 "api_test/file_system/open_existing_with_write")) << message_;
122 }
123
124 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698