| 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..8698f4b3597092e5aa2167d4111d966fc1f364e9 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,26 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {
|
|
|
| bool RunMediaGalleriesTestWithArg(const std::string& extension_name,
|
| const base::ListValue& custom_arg_value) {
|
| + // Copy the test data for this test into a temporary directory. Then add
|
| + // a common_injected.js to the temporary copy and run it.
|
| + 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_injected.js"));
|
| + base::FilePath inject_js_path(
|
| + temp_dir.path().AppendASCII(extension_name)
|
| + .AppendASCII("common_injected.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 +110,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());
|
| + return RunPlatformAppTestWithArg(extension_name, custom_arg);
|
| }
|
|
|
| void AttachFakeDevice() {
|
| @@ -113,10 +134,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 +152,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 +172,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 +211,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();
|
|
|
|
|