| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/first_run/first_run_helper.h" | 5 #include "ash/first_run/first_run_helper.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/system/tray/system_tray.h" | 7 #include "ash/system/tray/system_tray.h" |
| 8 #include "chrome/browser/chromeos/first_run/first_run.h" | 8 #include "chrome/browser/chromeos/first_run/first_run.h" |
| 9 #include "chrome/browser/chromeos/first_run/first_run_controller.h" | 9 #include "chrome/browser/chromeos/first_run/first_run_controller.h" |
| 10 #include "chrome/browser/chromeos/first_run/step_names.h" | 10 #include "chrome/browser/chromeos/first_run/step_names.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 if (!on_initialized_callback_.is_null()) | 28 if (!on_initialized_callback_.is_null()) |
| 29 on_initialized_callback_.Run(); | 29 on_initialized_callback_.Run(); |
| 30 controller()->OnActorInitialized(); | 30 controller()->OnActorInitialized(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 virtual void OnNextButtonClicked(const std::string& step_name) OVERRIDE { | 33 virtual void OnNextButtonClicked(const std::string& step_name) OVERRIDE { |
| 34 controller()->OnNextButtonClicked(step_name); | 34 controller()->OnNextButtonClicked(step_name); |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void OnStepShown(const std::string& step_name) OVERRIDE { | 37 virtual void OnStepShown(const std::string& step_name) OVERRIDE { |
| 38 current_step_name_ = step_name; |
| 38 if (!on_step_shown_callback_.is_null()) | 39 if (!on_step_shown_callback_.is_null()) |
| 39 on_step_shown_callback_.Run(); | 40 on_step_shown_callback_.Run(); |
| 40 controller()->OnStepShown(step_name); | 41 controller()->OnStepShown(step_name); |
| 41 } | 42 } |
| 42 | 43 |
| 43 virtual void OnStepHidden(const std::string& step_name) OVERRIDE { | 44 virtual void OnStepHidden(const std::string& step_name) OVERRIDE { |
| 44 controller()->OnStepHidden(step_name); | 45 controller()->OnStepHidden(step_name); |
| 45 } | 46 } |
| 46 | 47 |
| 47 virtual void OnHelpButtonClicked() OVERRIDE { | 48 virtual void OnHelpButtonClicked() OVERRIDE { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 70 | 71 |
| 71 void WaitForInitialization() { | 72 void WaitForInitialization() { |
| 72 if (initialized_) | 73 if (initialized_) |
| 73 return; | 74 return; |
| 74 WaitUntilCalled(&on_initialized_callback_); | 75 WaitUntilCalled(&on_initialized_callback_); |
| 75 EXPECT_TRUE(initialized_); | 76 EXPECT_TRUE(initialized_); |
| 76 js().set_web_contents(controller()->web_contents_for_tests_); | 77 js().set_web_contents(controller()->web_contents_for_tests_); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void WaitForStep(const std::string& step_name) { | 80 void WaitForStep(const std::string& step_name) { |
| 80 if (GetCurrentStepName() == step_name) | 81 if (current_step_name_ == step_name) |
| 81 return; | 82 return; |
| 82 WaitUntilCalled(&on_step_shown_callback_); | 83 WaitUntilCalled(&on_step_shown_callback_); |
| 83 EXPECT_EQ(GetCurrentStepName(), step_name); | 84 EXPECT_EQ(current_step_name_, step_name); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void AdvanceStep() { | 87 void AdvanceStep() { |
| 87 js().Evaluate("cr.FirstRun.currentStep_.nextButton_.click()"); | 88 js().Evaluate("cr.FirstRun.currentStep_.nextButton_.click()"); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void WaitForFinalization() { | 91 void WaitForFinalization() { |
| 91 if (!finalized_) { | 92 if (!finalized_) { |
| 92 WaitUntilCalled(&on_finalized_callback_); | 93 WaitUntilCalled(&on_finalized_callback_); |
| 93 EXPECT_TRUE(finalized_); | 94 EXPECT_TRUE(finalized_); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 void WaitUntilCalled(base::Closure* callback) { | 98 void WaitUntilCalled(base::Closure* callback) { |
| 98 scoped_refptr<content::MessageLoopRunner> runner = | 99 scoped_refptr<content::MessageLoopRunner> runner = |
| 99 new content::MessageLoopRunner; | 100 new content::MessageLoopRunner; |
| 100 *callback = runner->QuitClosure(); | 101 *callback = runner->QuitClosure(); |
| 101 runner->Run(); | 102 runner->Run(); |
| 102 callback->Reset(); | 103 callback->Reset(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 std::string GetCurrentStepName() { | |
| 106 return js().GetString( | |
| 107 "cr.FirstRun.currentStep_ ? cr.FirstRun.currentStep_.getName() : ''"); | |
| 108 } | |
| 109 | |
| 110 test::JSChecker& js() { return js_; } | 106 test::JSChecker& js() { return js_; } |
| 111 | 107 |
| 112 ash::FirstRunHelper* shell_helper() { | 108 ash::FirstRunHelper* shell_helper() { |
| 113 return controller()->shell_helper_.get(); | 109 return controller()->shell_helper_.get(); |
| 114 } | 110 } |
| 115 | 111 |
| 116 FirstRunController* controller() { | 112 FirstRunController* controller() { |
| 117 return FirstRunController::GetInstanceForTest(); | 113 return FirstRunController::GetInstanceForTest(); |
| 118 } | 114 } |
| 119 | 115 |
| 120 private: | 116 private: |
| 117 std::string current_step_name_; |
| 121 bool initialized_; | 118 bool initialized_; |
| 122 bool finalized_; | 119 bool finalized_; |
| 123 base::Closure on_initialized_callback_; | 120 base::Closure on_initialized_callback_; |
| 124 base::Closure on_step_shown_callback_; | 121 base::Closure on_step_shown_callback_; |
| 125 base::Closure on_finalized_callback_; | 122 base::Closure on_finalized_callback_; |
| 126 test::JSChecker js_; | 123 test::JSChecker js_; |
| 127 }; | 124 }; |
| 128 | 125 |
| 129 // Disabled due to flakiness, see http://crbug.com/335280 | 126 IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest, FirstRunFlow) { |
| 130 IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest, DISABLED_FirstRunFlow) { | |
| 131 LaunchTutorial(); | 127 LaunchTutorial(); |
| 132 WaitForInitialization(); | 128 WaitForInitialization(); |
| 133 WaitForStep(first_run::kAppListStep); | 129 WaitForStep(first_run::kAppListStep); |
| 134 EXPECT_FALSE(shell_helper()->IsTrayBubbleOpened()); | 130 EXPECT_FALSE(shell_helper()->IsTrayBubbleOpened()); |
| 135 AdvanceStep(); | 131 AdvanceStep(); |
| 136 WaitForStep(first_run::kTrayStep); | 132 WaitForStep(first_run::kTrayStep); |
| 137 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); | 133 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); |
| 138 AdvanceStep(); | 134 AdvanceStep(); |
| 139 WaitForStep(first_run::kHelpStep); | 135 WaitForStep(first_run::kHelpStep); |
| 140 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); | 136 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); |
| 141 AdvanceStep(); | 137 AdvanceStep(); |
| 142 WaitForFinalization(); | 138 WaitForFinalization(); |
| 143 content::RunAllPendingInMessageLoop(); | 139 content::RunAllPendingInMessageLoop(); |
| 144 EXPECT_EQ(controller(), (void*)NULL); | 140 EXPECT_EQ(controller(), (void*)NULL); |
| 145 // shell_helper() is destructed already, thats why we call Shell directly. | 141 // shell_helper() is destructed already, thats why we call Shell directly. |
| 146 EXPECT_FALSE(ash::Shell::GetInstance()->GetPrimarySystemTray()-> | 142 EXPECT_FALSE(ash::Shell::GetInstance()->GetPrimarySystemTray()-> |
| 147 HasSystemBubble()); | 143 HasSystemBubble()); |
| 148 } | 144 } |
| 149 | 145 |
| 150 } // namespace chromeos | 146 } // namespace chromeos |
| 151 | 147 |
| OLD | NEW |