| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/first_run/first_run_helper.h" | |
| 6 #include "ash/shell.h" | |
| 7 #include "ash/system/tray/system_tray.h" | |
| 8 #include "chrome/browser/chromeos/first_run/first_run.h" | |
| 9 #include "chrome/browser/chromeos/first_run/first_run_controller.h" | |
| 10 #include "chrome/browser/chromeos/first_run/step_names.h" | |
| 11 #include "chrome/browser/chromeos/login/test/js_checker.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "content/public/test/test_utils.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 class FirstRunUIBrowserTest : public InProcessBrowserTest, | |
| 18 public FirstRunActor::Delegate { | |
| 19 public: | |
| 20 FirstRunUIBrowserTest() | |
| 21 : initialized_(false), | |
| 22 finalized_(false) { | |
| 23 } | |
| 24 | |
| 25 // FirstRunActor::Delegate overrides. | |
| 26 void OnActorInitialized() override { | |
| 27 initialized_ = true; | |
| 28 if (!on_initialized_callback_.is_null()) | |
| 29 on_initialized_callback_.Run(); | |
| 30 controller()->OnActorInitialized(); | |
| 31 } | |
| 32 | |
| 33 void OnNextButtonClicked(const std::string& step_name) override { | |
| 34 controller()->OnNextButtonClicked(step_name); | |
| 35 } | |
| 36 | |
| 37 void OnStepShown(const std::string& step_name) override { | |
| 38 current_step_name_ = step_name; | |
| 39 if (!on_step_shown_callback_.is_null()) | |
| 40 on_step_shown_callback_.Run(); | |
| 41 controller()->OnStepShown(step_name); | |
| 42 } | |
| 43 | |
| 44 void OnStepHidden(const std::string& step_name) override { | |
| 45 controller()->OnStepHidden(step_name); | |
| 46 } | |
| 47 | |
| 48 void OnHelpButtonClicked() override { controller()->OnHelpButtonClicked(); } | |
| 49 | |
| 50 void OnActorFinalized() override { | |
| 51 finalized_ = true; | |
| 52 if (!on_finalized_callback_.is_null()) | |
| 53 on_finalized_callback_.Run(); | |
| 54 controller()->OnActorFinalized(); | |
| 55 } | |
| 56 | |
| 57 void OnActorDestroyed() override { controller()->OnActorDestroyed(); } | |
| 58 | |
| 59 void LaunchTutorial() { | |
| 60 chromeos::first_run::LaunchTutorial(); | |
| 61 EXPECT_TRUE(controller() != NULL); | |
| 62 // Replacing delegate to observe all messages coming from WebUI to | |
| 63 // controller. | |
| 64 controller()->actor_->set_delegate(this); | |
| 65 initialized_ = controller()->actor_->IsInitialized(); | |
| 66 } | |
| 67 | |
| 68 void WaitForInitialization() { | |
| 69 if (initialized_) | |
| 70 return; | |
| 71 WaitUntilCalled(&on_initialized_callback_); | |
| 72 EXPECT_TRUE(initialized_); | |
| 73 js().set_web_contents(controller()->web_contents_for_tests_); | |
| 74 } | |
| 75 | |
| 76 void WaitForStep(const std::string& step_name) { | |
| 77 if (current_step_name_ == step_name) | |
| 78 return; | |
| 79 WaitUntilCalled(&on_step_shown_callback_); | |
| 80 EXPECT_EQ(current_step_name_, step_name); | |
| 81 } | |
| 82 | |
| 83 void AdvanceStep() { | |
| 84 js().Evaluate("cr.FirstRun.currentStep_.nextButton_.click()"); | |
| 85 } | |
| 86 | |
| 87 void WaitForFinalization() { | |
| 88 if (!finalized_) { | |
| 89 WaitUntilCalled(&on_finalized_callback_); | |
| 90 EXPECT_TRUE(finalized_); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void WaitUntilCalled(base::Closure* callback) { | |
| 95 scoped_refptr<content::MessageLoopRunner> runner = | |
| 96 new content::MessageLoopRunner; | |
| 97 *callback = runner->QuitClosure(); | |
| 98 runner->Run(); | |
| 99 callback->Reset(); | |
| 100 } | |
| 101 | |
| 102 test::JSChecker& js() { return js_; } | |
| 103 | |
| 104 ash::FirstRunHelper* shell_helper() { | |
| 105 return controller()->shell_helper_.get(); | |
| 106 } | |
| 107 | |
| 108 FirstRunController* controller() { | |
| 109 return FirstRunController::GetInstanceForTest(); | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 std::string current_step_name_; | |
| 114 bool initialized_; | |
| 115 bool finalized_; | |
| 116 base::Closure on_initialized_callback_; | |
| 117 base::Closure on_step_shown_callback_; | |
| 118 base::Closure on_finalized_callback_; | |
| 119 test::JSChecker js_; | |
| 120 }; | |
| 121 | |
| 122 IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest, FirstRunFlow) { | |
| 123 LaunchTutorial(); | |
| 124 WaitForInitialization(); | |
| 125 WaitForStep(first_run::kAppListStep); | |
| 126 EXPECT_FALSE(shell_helper()->IsTrayBubbleOpened()); | |
| 127 AdvanceStep(); | |
| 128 WaitForStep(first_run::kTrayStep); | |
| 129 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); | |
| 130 AdvanceStep(); | |
| 131 WaitForStep(first_run::kHelpStep); | |
| 132 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened()); | |
| 133 AdvanceStep(); | |
| 134 WaitForFinalization(); | |
| 135 content::RunAllPendingInMessageLoop(); | |
| 136 EXPECT_EQ(controller(), (void*)NULL); | |
| 137 // shell_helper() is destructed already, thats why we call Shell directly. | |
| 138 EXPECT_FALSE(ash::Shell::GetInstance()->GetPrimarySystemTray()-> | |
| 139 HasSystemBubble()); | |
| 140 } | |
| 141 | |
| 142 } // namespace chromeos | |
| 143 | |
| OLD | NEW |