| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // We do not want to bother with posting tasks to create a temp dir. | 206 // We do not want to bother with posting tasks to create a temp dir. |
| 207 // Just allow IO from main thread for now. | 207 // Just allow IO from main thread for now. |
| 208 base::ThreadRestrictions::SetIOAllowed(true); | 208 base::ThreadRestrictions::SetIOAllowed(true); |
| 209 | 209 |
| 210 EXPECT_TRUE(embedded_test_server()->Start()); | 210 EXPECT_TRUE(embedded_test_server()->Start()); |
| 211 | 211 |
| 212 base::ScopedTempDir user_data_dir; | 212 base::ScopedTempDir user_data_dir; |
| 213 ASSERT_TRUE(user_data_dir.CreateUniqueTempDir()); | 213 ASSERT_TRUE(user_data_dir.CreateUniqueTempDir()); |
| 214 | 214 |
| 215 // Newly created temp directory should be empty. | 215 // Newly created temp directory should be empty. |
| 216 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.path())); | 216 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.GetPath())); |
| 217 | 217 |
| 218 HeadlessBrowserContext* browser_context = | 218 HeadlessBrowserContext* browser_context = |
| 219 browser() | 219 browser() |
| 220 ->CreateBrowserContextBuilder() | 220 ->CreateBrowserContextBuilder() |
| 221 .SetUserDataDir(user_data_dir.path()) | 221 .SetUserDataDir(user_data_dir.GetPath()) |
| 222 .SetIncognitoMode(false) | 222 .SetIncognitoMode(false) |
| 223 .Build(); | 223 .Build(); |
| 224 | 224 |
| 225 HeadlessWebContents* web_contents = | 225 HeadlessWebContents* web_contents = |
| 226 browser_context->CreateWebContentsBuilder() | 226 browser_context->CreateWebContentsBuilder() |
| 227 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) | 227 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) |
| 228 .Build(); | 228 .Build(); |
| 229 | 229 |
| 230 EXPECT_TRUE(WaitForLoad(web_contents)); | 230 EXPECT_TRUE(WaitForLoad(web_contents)); |
| 231 | 231 |
| 232 // Something should be written to this directory. | 232 // Something should be written to this directory. |
| 233 // If it is not the case, more complex page may be needed. | 233 // If it is not the case, more complex page may be needed. |
| 234 // ServiceWorkers may be a good option. | 234 // ServiceWorkers may be a good option. |
| 235 EXPECT_FALSE(base::IsDirectoryEmpty(user_data_dir.path())); | 235 EXPECT_FALSE(base::IsDirectoryEmpty(user_data_dir.GetPath())); |
| 236 } | 236 } |
| 237 | 237 |
| 238 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, IncognitoMode) { | 238 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, IncognitoMode) { |
| 239 // We do not want to bother with posting tasks to create a temp dir. | 239 // We do not want to bother with posting tasks to create a temp dir. |
| 240 // Just allow IO from main thread for now. | 240 // Just allow IO from main thread for now. |
| 241 base::ThreadRestrictions::SetIOAllowed(true); | 241 base::ThreadRestrictions::SetIOAllowed(true); |
| 242 | 242 |
| 243 EXPECT_TRUE(embedded_test_server()->Start()); | 243 EXPECT_TRUE(embedded_test_server()->Start()); |
| 244 | 244 |
| 245 base::ScopedTempDir user_data_dir; | 245 base::ScopedTempDir user_data_dir; |
| 246 ASSERT_TRUE(user_data_dir.CreateUniqueTempDir()); | 246 ASSERT_TRUE(user_data_dir.CreateUniqueTempDir()); |
| 247 | 247 |
| 248 // Newly created temp directory should be empty. | 248 // Newly created temp directory should be empty. |
| 249 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.path())); | 249 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.GetPath())); |
| 250 | 250 |
| 251 HeadlessBrowserContext* browser_context = | 251 HeadlessBrowserContext* browser_context = |
| 252 browser() | 252 browser() |
| 253 ->CreateBrowserContextBuilder() | 253 ->CreateBrowserContextBuilder() |
| 254 .SetUserDataDir(user_data_dir.path()) | 254 .SetUserDataDir(user_data_dir.GetPath()) |
| 255 .SetIncognitoMode(true) | 255 .SetIncognitoMode(true) |
| 256 .Build(); | 256 .Build(); |
| 257 | 257 |
| 258 HeadlessWebContents* web_contents = | 258 HeadlessWebContents* web_contents = |
| 259 browser_context->CreateWebContentsBuilder() | 259 browser_context->CreateWebContentsBuilder() |
| 260 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) | 260 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) |
| 261 .Build(); | 261 .Build(); |
| 262 | 262 |
| 263 EXPECT_TRUE(WaitForLoad(web_contents)); | 263 EXPECT_TRUE(WaitForLoad(web_contents)); |
| 264 | 264 |
| 265 // Similar to test above, but now we are in incognito mode, | 265 // Similar to test above, but now we are in incognito mode, |
| 266 // so nothing should be written to this directory. | 266 // so nothing should be written to this directory. |
| 267 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.path())); | 267 EXPECT_TRUE(base::IsDirectoryEmpty(user_data_dir.GetPath())); |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace headless | 270 } // namespace headless |
| OLD | NEW |