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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc

Issue 10822002: Media Galleries API: hookup the AllGalleries permission and add tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h"
7 #include "base/file_util.h"
8 #include "base/path_service.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 10 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
11 #include "chrome/common/chrome_paths.h"
7 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
8 13
14 #if defined(OS_LINUX)
15 #include <fstream>
16
17 #include "base/environment.h"
18 #include "base/scoped_temp_dir.h"
19 #endif
20
9 namespace { 21 namespace {
10 22
11 class MediaGalleriesApiTest: public PlatformAppBrowserTest { 23 class ExperimentalMediaGalleriesApiTest : public ExtensionApiTest {
12 public: 24 public:
13 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
14 PlatformAppBrowserTest::SetUpCommandLine(command_line); 26 ExtensionApiTest::SetUpCommandLine(command_line);
15 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 27 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
16 } 28 }
17 }; 29 };
18 30
31 class EnsurePictureDirectoryExists {
32 public:
33 EnsurePictureDirectoryExists() {
34 Init();
35 }
36
37 private:
38 void Init() {
39 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
40 return;
41 #elif defined(OS_LINUX)
42 // On Linux, the picture directory probably doesn't exist by default,
43 // so we override the settings to point to a tempdir.
44 ASSERT_TRUE(xdg_dir_.CreateUniqueTempDir());
45
46 FilePath config_file(xdg_dir_.path().Append("user-dirs.dirs"));
47 std::ofstream file;
48 file.open(config_file.value().c_str());
49 ASSERT_TRUE(file.is_open());
50 file << "XDG_PICTURES_DIR=\"" << xdg_dir_.path().value() << "\"";
51 file.close();
52
53 scoped_ptr<base::Environment> env(base::Environment::Create());
54 env->SetVar("XDG_CONFIG_HOME", xdg_dir_.path().value());
55 #else
56 FilePath pictures_path;
57 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path));
58 ASSERT_TRUE(file_util::DirectoryExists(pictures_path));
59 #endif
60 }
61
62 #if defined(OS_LINUX)
63 ScopedTempDir xdg_dir_;
64 #endif
65 };
66
67
19 } // namespace 68 } // namespace
20 69
21 IN_PROC_BROWSER_TEST_F(MediaGalleriesApiTest, MediaGalleries) { 70 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, NoGalleries) {
22 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries")) << message_; 71 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_galleries"))
72 << message_;
23 } 73 }
74
75 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MediaGalleriesRead) {
76 EnsurePictureDirectoryExists picture_directory;
77 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/read_access"))
78 << message_;
79 }
80
81 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MediaGalleriesNoAccess) {
82 EnsurePictureDirectoryExists picture_directory;
83 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access"))
84 << message_;
85 }
86
87 IN_PROC_BROWSER_TEST_F(ExperimentalMediaGalleriesApiTest,
88 ExperimentalMediaGalleries) {
89 ASSERT_TRUE(RunExtensionTest("media_galleries/experimental")) << message_;
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698