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

Unified Diff: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc

Issue 24420003: Media Galleries: Run API tests in a temp directory with an injected common.js file. Avoid the need … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make it more obvious there's a JS file being injected into the test cases (try 2) Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698