OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/test/ui/ui_test.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/path_service.h" | |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/chrome_notification_types.h" | |
11 #include "chrome/browser/ui/browser.h" | |
12 #include "chrome/browser/ui/browser_commands.h" | |
13 #include "chrome/browser/user_data_dir_extractor_win.h" | |
14 #include "chrome/common/chrome_paths.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/test/base/in_process_browser_test.h" | |
17 #include "chrome/test/base/ui_test_utils.h" | |
18 | |
19 // These tests only apply to the Windows version; see chrome_browser_main.cc: | |
20 // function GetUserDataDir() for details. | |
21 class ChromeMainUserDataDirTest : public InProcessBrowserTest { | |
22 public: | |
23 ChromeMainUserDataDirTest() | |
24 : did_get_user_data_dir_(false), | |
25 did_create_local_state_before_get_user_data_dir_(false) {} | |
26 | |
27 bool did_get_user_data_dir() const { return did_get_user_data_dir_; } | |
28 bool did_create_local_state_before_get_user_data_dir() const { | |
29 return did_create_local_state_before_get_user_data_dir_; | |
30 } | |
31 | |
32 protected: | |
33 virtual void SetUp() OVERRIDE { | |
34 // Install custom GetUserDataDir callback. | |
35 callback_ = base::Bind(&ChromeMainUserDataDirTest::GetUserDataDirCallback, | |
36 this); | |
37 chrome::InstallCustomGetUserDataDirCallbackForTest(&callback_); | |
38 | |
39 InProcessBrowserTest::SetUp(); | |
40 } | |
41 | |
42 private: | |
43 base::FilePath GetUserDataDirCallback() { | |
44 did_get_user_data_dir_ = true; | |
45 did_create_local_state_before_get_user_data_dir_ = | |
46 g_browser_process && g_browser_process->created_local_state(); | |
47 | |
48 base::FilePath user_data_dir; | |
49 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
50 return user_data_dir; | |
51 } | |
52 | |
53 chrome::GetUserDataDirCallback callback_; | |
54 bool did_get_user_data_dir_; | |
55 bool did_create_local_state_before_get_user_data_dir_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(ChromeMainUserDataDirTest); | |
58 }; | |
59 | |
60 IN_PROC_BROWSER_TEST_F(ChromeMainUserDataDirTest, GetUserDataDir) { | |
61 // Verify that GetUserDataDir() has been invoked. | |
62 ASSERT_TRUE(did_get_user_data_dir()); | |
63 | |
64 // Verify that local state was not created before invoking GetUserDataDir(). | |
65 ASSERT_FALSE(did_create_local_state_before_get_user_data_dir()); | |
66 | |
67 // Verify that we have a valid browser process. | |
68 ASSERT_TRUE(g_browser_process); | |
69 | |
70 // Verify that local state is created now. | |
71 ASSERT_TRUE(g_browser_process->created_local_state()); | |
72 } | |
OLD | NEW |