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.
5 #include "ash/first_run/first_run_helper.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"
17 class FirstRunUIBrowserTest
: public InProcessBrowserTest
,
18 public FirstRunActor::Delegate
{
20 FirstRunUIBrowserTest()
21 : initialized_(false),
25 // FirstRunActor::Delegate overrides.
26 virtual void OnActorInitialized() override
{
28 if (!on_initialized_callback_
.is_null())
29 on_initialized_callback_
.Run();
30 controller()->OnActorInitialized();
33 virtual void OnNextButtonClicked(const std::string
& step_name
) override
{
34 controller()->OnNextButtonClicked(step_name
);
37 virtual 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
);
44 virtual void OnStepHidden(const std::string
& step_name
) override
{
45 controller()->OnStepHidden(step_name
);
48 virtual void OnHelpButtonClicked() override
{
49 controller()->OnHelpButtonClicked();
52 virtual void OnActorFinalized() override
{
54 if (!on_finalized_callback_
.is_null())
55 on_finalized_callback_
.Run();
56 controller()->OnActorFinalized();
59 virtual void OnActorDestroyed() override
{
60 controller()->OnActorDestroyed();
63 void LaunchTutorial() {
64 chromeos::first_run::LaunchTutorial();
65 EXPECT_TRUE(controller() != NULL
);
66 // Replacing delegate to observe all messages coming from WebUI to
68 controller()->actor_
->set_delegate(this);
69 initialized_
= controller()->actor_
->IsInitialized();
72 void WaitForInitialization() {
75 WaitUntilCalled(&on_initialized_callback_
);
76 EXPECT_TRUE(initialized_
);
77 js().set_web_contents(controller()->web_contents_for_tests_
);
80 void WaitForStep(const std::string
& step_name
) {
81 if (current_step_name_
== step_name
)
83 WaitUntilCalled(&on_step_shown_callback_
);
84 EXPECT_EQ(current_step_name_
, step_name
);
88 js().Evaluate("cr.FirstRun.currentStep_.nextButton_.click()");
91 void WaitForFinalization() {
93 WaitUntilCalled(&on_finalized_callback_
);
94 EXPECT_TRUE(finalized_
);
98 void WaitUntilCalled(base::Closure
* callback
) {
99 scoped_refptr
<content::MessageLoopRunner
> runner
=
100 new content::MessageLoopRunner
;
101 *callback
= runner
->QuitClosure();
106 test::JSChecker
& js() { return js_
; }
108 ash::FirstRunHelper
* shell_helper() {
109 return controller()->shell_helper_
.get();
112 FirstRunController
* controller() {
113 return FirstRunController::GetInstanceForTest();
117 std::string current_step_name_
;
120 base::Closure on_initialized_callback_
;
121 base::Closure on_step_shown_callback_
;
122 base::Closure on_finalized_callback_
;
126 IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest
, FirstRunFlow
) {
128 WaitForInitialization();
129 WaitForStep(first_run::kAppListStep
);
130 EXPECT_FALSE(shell_helper()->IsTrayBubbleOpened());
132 WaitForStep(first_run::kTrayStep
);
133 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened());
135 WaitForStep(first_run::kHelpStep
);
136 EXPECT_TRUE(shell_helper()->IsTrayBubbleOpened());
138 WaitForFinalization();
139 content::RunAllPendingInMessageLoop();
140 EXPECT_EQ(controller(), (void*)NULL
);
141 // shell_helper() is destructed already, thats why we call Shell directly.
142 EXPECT_FALSE(ash::Shell::GetInstance()->GetPrimarySystemTray()->
146 } // namespace chromeos