OLD | NEW |
---|---|
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" | 6 #include "base/file_path.h" |
Lei Zhang
2012/11/09 09:14:53
remove unused includes.
vandebo (ex-Chrome)
2012/11/13 06:50:18
Done.
| |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_process_manager.h" | 12 #include "chrome/browser/extensions/extension_process_manager.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 14 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
15 #include "chrome/browser/media_gallery/media_galleries_test_util.h" | |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
19 | 20 |
20 #if defined(OS_LINUX) | 21 #if defined(OS_LINUX) |
21 #include "base/environment.h" | 22 #include "base/environment.h" |
22 #include "base/scoped_temp_dir.h" | 23 #include "base/scoped_temp_dir.h" |
23 #endif | 24 #endif |
24 | 25 |
(...skipping 22 matching lines...) Expand all Loading... | |
47 | 48 |
48 static const char kTestGalleries[] = "testGalleries(%d)"; | 49 static const char kTestGalleries[] = "testGalleries(%d)"; |
49 ResultCatcher catcher; | 50 ResultCatcher catcher; |
50 host->render_view_host()->ExecuteJavascriptInWebFrame( | 51 host->render_view_host()->ExecuteJavascriptInWebFrame( |
51 string16(), | 52 string16(), |
52 ASCIIToUTF16(base::StringPrintf(kTestGalleries, expected_galleries))); | 53 ASCIIToUTF16(base::StringPrintf(kTestGalleries, expected_galleries))); |
53 EXPECT_TRUE(catcher.GetNextResult()) << message_; | 54 EXPECT_TRUE(catcher.GetNextResult()) << message_; |
54 } | 55 } |
55 }; | 56 }; |
56 | 57 |
57 class EnsureMediaDirectoriesExists { | |
58 public: | |
59 EnsureMediaDirectoriesExists() : num_galleries_(0) { | |
60 Init(); | |
61 } | |
62 | |
63 int num_galleries() const { return num_galleries_; } | |
64 | |
65 private: | |
66 void Init() { | |
67 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | |
68 return; | |
69 #elif defined(OS_LINUX) | |
70 // On Linux, the media directories may not exist by default, so override | |
71 // the settings to point to a temp directory with the media directories. | |
72 ASSERT_TRUE(xdg_dir_.CreateUniqueTempDir()); | |
73 const FilePath xdg_path = xdg_dir_.path(); | |
74 const FilePath music_dir(xdg_path.Append("Megaman")); | |
75 const FilePath pictures_dir(xdg_path.Append("Pitfall")); | |
76 const FilePath videos_dir(xdg_path.Append("VVVV")); | |
77 ASSERT_TRUE(file_util::CreateDirectory(music_dir)); | |
78 ASSERT_TRUE(file_util::CreateDirectory(pictures_dir)); | |
79 ASSERT_TRUE(file_util::CreateDirectory(videos_dir)); | |
80 | |
81 const FilePath config_file(xdg_path.Append("user-dirs.dirs")); | |
82 std::string xdg_user_dir_data = base::StringPrintf( | |
83 "XDG_MUSIC_DIR=\"%s\"\n" | |
84 "XDG_PICTURES_DIR=\"%s\"\n" | |
85 "XDG_VIDEOS_DIR=\"%s\"\n", | |
86 music_dir.value().c_str(), | |
87 pictures_dir.value().c_str(), | |
88 videos_dir.value().c_str()); | |
89 ASSERT_TRUE(file_util::WriteFile(config_file, | |
90 xdg_user_dir_data.c_str(), | |
91 xdg_user_dir_data.size())); | |
92 | |
93 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
94 env->SetVar("XDG_CONFIG_HOME", xdg_path.value()); | |
95 | |
96 num_galleries_ = 3; | |
97 #else | |
98 const int kDirectoryKeys[] = { | |
99 chrome::DIR_USER_MUSIC, | |
100 chrome::DIR_USER_PICTURES, | |
101 chrome::DIR_USER_VIDEOS, | |
102 }; | |
103 | |
104 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { | |
105 FilePath path; | |
106 if (PathService::Get(kDirectoryKeys[i], &path) && | |
107 file_util::DirectoryExists(path)) { | |
108 ++num_galleries_; | |
109 } | |
110 } | |
111 ASSERT_GT(num_galleries_, 0); | |
112 #endif | |
113 } | |
114 | |
115 #if defined(OS_LINUX) | |
116 ScopedTempDir xdg_dir_; | |
117 #endif | |
118 | |
119 int num_galleries_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(EnsureMediaDirectoriesExists); | |
122 }; | |
123 | |
124 } // namespace | 58 } // namespace |
125 | 59 |
126 IN_PROC_BROWSER_TEST_F(PlatformAppMediaGalleriesBrowserTest, NoGalleries) { | 60 IN_PROC_BROWSER_TEST_F(PlatformAppMediaGalleriesBrowserTest, NoGalleries) { |
127 EnsureMediaDirectoriesExists media_directories; | 61 EnsureMediaDirectoriesExists media_directories; |
128 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_galleries")) | 62 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_galleries")) |
129 << message_; | 63 << message_; |
130 } | 64 } |
131 | 65 |
132 IN_PROC_BROWSER_TEST_F(PlatformAppMediaGalleriesBrowserTest, | 66 IN_PROC_BROWSER_TEST_F(PlatformAppMediaGalleriesBrowserTest, |
133 MediaGalleriesRead) { | 67 MediaGalleriesRead) { |
(...skipping 10 matching lines...) Expand all Loading... | |
144 ASSERT_TRUE(RunPlatformAppTestReturnImmediately( | 78 ASSERT_TRUE(RunPlatformAppTestReturnImmediately( |
145 "api_test/media_galleries/no_access")) << message_; | 79 "api_test/media_galleries/no_access")) << message_; |
146 RunSecondTestPhase(media_directories.num_galleries()); | 80 RunSecondTestPhase(media_directories.num_galleries()); |
147 CloseShellWindowsAndWaitForAppToExit(); | 81 CloseShellWindowsAndWaitForAppToExit(); |
148 } | 82 } |
149 | 83 |
150 IN_PROC_BROWSER_TEST_F(ExperimentalMediaGalleriesApiTest, | 84 IN_PROC_BROWSER_TEST_F(ExperimentalMediaGalleriesApiTest, |
151 ExperimentalMediaGalleries) { | 85 ExperimentalMediaGalleries) { |
152 ASSERT_TRUE(RunExtensionTest("media_galleries/experimental")) << message_; | 86 ASSERT_TRUE(RunExtensionTest("media_galleries/experimental")) << message_; |
153 } | 87 } |
OLD | NEW |