Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/chromeos/first_run/goodies_displayer.h" | 7 #include "chrome/browser/chromeos/first_run/goodies_displayer.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/test_launcher_utils.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 16 | 17 |
| 17 namespace chromeos { | 18 namespace chromeos { |
| 18 | 19 |
| 19 class GoodiesDisplayerBrowserTest : public InProcessBrowserTest { | 20 class GoodiesDisplayerBrowserTest : public InProcessBrowserTest, |
| 21 public testing::WithParamInterface<bool> { | |
| 20 public: | 22 public: |
| 21 GoodiesDisplayerBrowserTest() {} | 23 GoodiesDisplayerBrowserTest() {} |
| 22 | 24 |
| 23 protected: | 25 protected: |
| 24 ~GoodiesDisplayerBrowserTest() override { | 26 ~GoodiesDisplayerBrowserTest() override { |
| 25 first_run::GoodiesDisplayer::Delete(); | 27 first_run::GoodiesDisplayer::Delete(); |
| 26 } | 28 } |
| 27 | 29 |
| 28 // Set up windowless browser and GoodiesDisplayer. |delta_days| is +/- delta | 30 // Set up windowless browser and GoodiesDisplayer. |delta_days| is +/- delta |
| 29 // in days from kMaxDaysAfterOobeForGoodies; <= 0: "show", > 0: "don't show". | 31 // in days from kMaxDaysAfterOobeForGoodies; <= 0: "show", > 0: "don't show". |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 54 for (int index = 0; index < tab_count; index++) { | 56 for (int index = 0; index < tab_count; index++) { |
| 55 const std::string tab_url = browser->tab_strip_model() | 57 const std::string tab_url = browser->tab_strip_model() |
| 56 ->GetWebContentsAt(index)->GetVisibleURL().spec(); | 58 ->GetWebContentsAt(index)->GetVisibleURL().spec(); |
| 57 if (tab_url == first_run::GoodiesDisplayer::kGoodiesURL) | 59 if (tab_url == first_run::GoodiesDisplayer::kGoodiesURL) |
| 58 ++goodies_tab_count; | 60 ++goodies_tab_count; |
| 59 } | 61 } |
| 60 EXPECT_EQ(expected_tabs, tab_count); | 62 EXPECT_EQ(expected_tabs, tab_count); |
| 61 EXPECT_EQ(expected_goodies_tabs, goodies_tab_count); | 63 EXPECT_EQ(expected_goodies_tabs, goodies_tab_count); |
| 62 } | 64 } |
| 63 | 65 |
| 66 // Is --no-first-run specified? | |
| 67 bool NoFirstRunSpecified() const { return GetParam(); } | |
| 68 | |
| 64 private: | 69 private: |
| 65 void WaitForGoodiesSetup() { | 70 void WaitForGoodiesSetup() { |
| 66 if (setup_info_.setup_complete) | 71 if (setup_info_.setup_complete) |
| 67 return; | 72 return; |
| 68 | 73 |
| 69 // Wait for GoodiesDisplayer setup completion. The completion callback will | 74 // Wait for GoodiesDisplayer setup completion. The completion callback will |
| 70 // shut down the message loop. | 75 // shut down the message loop. |
| 71 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 76 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 72 new content::MessageLoopRunner; | 77 new content::MessageLoopRunner; |
| 73 setup_info_.on_setup_complete_callback = message_loop_runner->QuitClosure(); | 78 setup_info_.on_setup_complete_callback = message_loop_runner->QuitClosure(); |
| 74 message_loop_runner->Run(); | 79 message_loop_runner->Run(); |
| 75 setup_info_.on_setup_complete_callback.Reset(); | 80 setup_info_.on_setup_complete_callback.Reset(); |
| 76 EXPECT_TRUE(setup_info_.setup_complete); | 81 EXPECT_TRUE(setup_info_.setup_complete); |
| 77 } | 82 } |
| 78 | 83 |
| 79 // InProcessBrowserTest overrides. | 84 // InProcessBrowserTest overrides. |
| 80 void SetUpCommandLine(base::CommandLine* command_line) override { | 85 void SetUpDefaultCommandLine(base::CommandLine* command_line) override { |
| 81 // Don't want a browser window until GoodiesDisplayer is observing. | 86 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); |
| 87 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); | |
| 88 if (NoFirstRunSpecified()) { // --no-first-run is present by default. | |
|
Greg Levin
2016/11/22 00:13:40
Does this mean that this flag is present in the de
achuithb
2016/11/22 00:38:47
Yup, default browser tests specify --no-first-run
| |
| 89 *command_line = default_command_line; | |
| 90 ASSERT_TRUE(command_line->HasSwitch(switches::kNoFirstRun)); | |
| 91 } else { // Remove --no-first-run. | |
| 92 test_launcher_utils::RemoveCommandLineSwitch( | |
| 93 default_command_line, switches::kNoFirstRun, command_line); | |
| 94 } | |
| 82 command_line->AppendSwitch(switches::kNoStartupWindow); | 95 command_line->AppendSwitch(switches::kNoStartupWindow); |
| 83 } | 96 } |
| 84 | 97 |
| 85 first_run::GoodiesDisplayerTestInfo setup_info_; | 98 first_run::GoodiesDisplayerTestInfo setup_info_; |
| 86 }; | 99 }; |
| 87 | 100 |
| 88 // Tests that the Goodies page is not shown on older device. | 101 // Tests that the Goodies page is not shown on older device. |
| 89 IN_PROC_BROWSER_TEST_F(GoodiesDisplayerBrowserTest, OldDeviceNoDisplay) { | 102 IN_PROC_BROWSER_TEST_P(GoodiesDisplayerBrowserTest, OldDeviceNoDisplay) { |
| 103 if (NoFirstRunSpecified()) // --no-first-run disables Goodies page. | |
| 104 return; | |
| 105 | |
| 90 EXPECT_TRUE(g_browser_process->local_state()->GetBoolean( | 106 EXPECT_TRUE(g_browser_process->local_state()->GetBoolean( |
| 91 prefs::kCanShowOobeGoodiesPage)); | 107 prefs::kCanShowOobeGoodiesPage)); |
| 92 | 108 |
| 93 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); | 109 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 94 Browser* browser = CreateBrowserAndDisplayer(1); // 1 day too old. | 110 Browser* browser = CreateBrowserAndDisplayer(1); // 1 day too old. |
| 95 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); | 111 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 96 | 112 |
| 97 AddBlankTabAndShow(browser); | 113 AddBlankTabAndShow(browser); |
| 98 ExpectTabCounts(browser, 1, 0); // Shouldn't show Goodies tab. | 114 ExpectTabCounts(browser, 1, 0); // Shouldn't show Goodies tab. |
| 99 EXPECT_FALSE(g_browser_process->local_state()->GetBoolean( | 115 EXPECT_FALSE(g_browser_process->local_state()->GetBoolean( |
| 100 prefs::kCanShowOobeGoodiesPage)); | 116 prefs::kCanShowOobeGoodiesPage)); |
| 101 } | 117 } |
| 102 | 118 |
| 103 // Tests that the Goodies page is shown, only once, on non-incognito browser | 119 // Tests that the Goodies page is shown, only once, on non-incognito browser |
| 104 // when device isn't too old. | 120 // when device isn't too old, and when --no-first-run is not specified. |
| 105 IN_PROC_BROWSER_TEST_F(GoodiesDisplayerBrowserTest, DisplayGoodies) { | 121 IN_PROC_BROWSER_TEST_P(GoodiesDisplayerBrowserTest, DisplayGoodies) { |
| 106 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); | 122 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 107 Browser* browser = CreateBrowserAndDisplayer(-1); | 123 Browser* browser = CreateBrowserAndDisplayer(-1); |
| 108 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); | 124 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 109 | 125 |
| 110 // Shouldn't show Goodies tab in incognito mode. | 126 // Shouldn't show Goodies tab in incognito mode. |
| 111 Browser* incognito_browser = new Browser( | 127 Browser* incognito_browser = new Browser( |
| 112 Browser::CreateParams(browser->profile()->GetOffTheRecordProfile())); | 128 Browser::CreateParams(browser->profile()->GetOffTheRecordProfile())); |
| 113 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | 129 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 114 AddBlankTabAndShow(incognito_browser); | 130 AddBlankTabAndShow(incognito_browser); |
| 115 ExpectTabCounts(incognito_browser, 1, 0); | 131 ExpectTabCounts(incognito_browser, 1, 0); |
| 116 CloseBrowserSynchronously(incognito_browser); | 132 CloseBrowserSynchronously(incognito_browser); |
| 117 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); | 133 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 118 EXPECT_TRUE(g_browser_process->local_state()->GetBoolean( | 134 EXPECT_TRUE(g_browser_process->local_state()->GetBoolean( |
| 119 prefs::kCanShowOobeGoodiesPage)); | 135 prefs::kCanShowOobeGoodiesPage)); |
| 120 | 136 |
| 121 // First logged-in browser shows Goodies. | 137 // First logged-in browser shows Goodies if --no-first-run is not specified. |
| 122 AddBlankTabAndShow(browser); | 138 AddBlankTabAndShow(browser); |
| 123 ExpectTabCounts(browser, 2, 1); | 139 if (NoFirstRunSpecified()) |
| 140 ExpectTabCounts(browser, 1, 0); | |
| 141 else | |
| 142 ExpectTabCounts(browser, 2, 1); | |
| 143 | |
| 124 EXPECT_FALSE(g_browser_process->local_state()->GetBoolean( | 144 EXPECT_FALSE(g_browser_process->local_state()->GetBoolean( |
| 125 prefs::kCanShowOobeGoodiesPage)); | 145 prefs::kCanShowOobeGoodiesPage)); |
| 126 | 146 |
| 127 // Next time a browser is opened, no Goodies. | 147 // Next time a browser is opened, no Goodies. |
| 128 Browser* browser2 = CreateBrowser(browser->profile()); | 148 Browser* browser2 = CreateBrowser(browser->profile()); |
| 129 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | 149 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 130 ExpectTabCounts(browser2, 1, 0); | 150 ExpectTabCounts(browser2, 1, 0); |
| 131 } | 151 } |
| 132 | 152 |
| 153 INSTANTIATE_TEST_CASE_P(/* no prefix */, | |
| 154 GoodiesDisplayerBrowserTest, | |
| 155 testing::Values(true, false)); | |
| 156 | |
| 133 } // namespace chromeos | 157 } // namespace chromeos |
| 134 | 158 |
| OLD | NEW |