Chromium Code Reviews| Index: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc |
| diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc |
| index 811ba903759bf0c0d0e13a9b2b1660d2c4c4c215..ff32daacc0efe7d4bec89f7b18f48cefcd62c841 100644 |
| --- a/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc |
| +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/auto_reset.h" |
| #include "base/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/json/json_writer.h" |
| @@ -82,6 +83,22 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| bool RunMediaGalleriesTestWithArg(const std::string& extension_name, |
| const base::ListValue& custom_arg_value) { |
| + const char kTestDir[] = "api_test/media_galleries/"; |
| + base::FilePath from_dir = |
| + test_data_dir_.AppendASCII(kTestDir + extension_name); |
| + base::ScopedTempDir temp_dir; |
| + if (!temp_dir.CreateUniqueTempDir()) |
| + return false; |
| + |
| + if (!base::CopyDirectory(from_dir, temp_dir.path(), true)) |
| + return false; |
| + |
| + base::FilePath common_js_path(GetCommonDataDir().AppendASCII("common.js")); |
| + base::FilePath inject_js_path(temp_dir.path().AppendASCII(extension_name) |
| + .AppendASCII("common.js")); |
| + if (!base::CopyFile(common_js_path, inject_js_path)) |
| + return false; |
| + |
| const char* custom_arg = NULL; |
| std::string json_string; |
| if (!custom_arg_value.empty()) { |
| @@ -89,8 +106,8 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| custom_arg = json_string.c_str(); |
| } |
| - const char kTestDir[] = "api_test/media_galleries/"; |
| - return RunPlatformAppTestWithArg(kTestDir + extension_name, custom_arg); |
| + base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path()); |
|
tommycli
2013/09/24 23:26:10
This override and the above copying logic probably
Lei Zhang
2013/09/24 23:41:57
I would like to just make common.js available to a
|
| + return RunPlatformAppTestWithArg(extension_name, custom_arg); |
| } |
| void AttachFakeDevice() { |
| @@ -113,10 +130,7 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| if (ensure_media_directories_exist_->num_galleries() == 0) |
| return; |
| - base::FilePath test_data_path = |
| - test_data_dir_.AppendASCII("api_test") |
| - .AppendASCII("media_galleries") |
| - .AppendASCII("common"); |
| + base::FilePath test_data_path(GetCommonDataDir()); |
| base::FilePath write_path; |
| ASSERT_TRUE(PathService::Get(chrome::DIR_USER_PICTURES, &write_path)); |
| @@ -134,6 +148,12 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| test_jpg_size_ = base::checked_numeric_cast<int>(file_size); |
| } |
| + base::FilePath GetCommonDataDir() const { |
| + return test_data_dir_.AppendASCII("api_test") |
| + .AppendASCII("media_galleries") |
| + .AppendASCII("common"); |
| + } |
| + |
| int num_galleries() const { |
| return ensure_media_directories_exist_->num_galleries(); |
| } |
| @@ -148,8 +168,12 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| MediaGalleriesNoAccess) { |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + MakeFakeMediaGalleryForTest(browser()->profile(), temp_dir.path()); |
| + |
| base::ListValue custom_args; |
| - custom_args.AppendInteger(num_galleries()); |
| + custom_args.AppendInteger(num_galleries() + 1); |
| ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args)) |
| << message_; |
| @@ -183,14 +207,6 @@ IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| } |
| IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| - MediaGalleriesCopyToNoAccess) { |
| - base::ScopedTempDir temp_dir; |
| - ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| - MakeFakeMediaGalleryForTest(browser()->profile(), temp_dir.path()); |
| - ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access/no_access")) << message_; |
| -} |
| - |
| -IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| MediaGalleriesAccessAttached) { |
| AttachFakeDevice(); |