| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/speech/speech_recognition_bubble_controller.h" | 7 #include "chrome/browser/speech/speech_recognition_bubble_controller.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 io_thread_.Start(); | 120 io_thread_.Start(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 virtual void TearDown() { | 123 virtual void TearDown() { |
| 124 SpeechRecognitionBubble::set_factory(NULL); | 124 SpeechRecognitionBubble::set_factory(NULL); |
| 125 io_thread_.Stop(); | 125 io_thread_.Stop(); |
| 126 BrowserWithTestWindowTest::TearDown(); | 126 BrowserWithTestWindowTest::TearDown(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 static void ActivateBubble() { | 129 static void ActivateBubble() { |
| 130 if (MockSpeechRecognitionBubble::type() == | 130 if (MockSpeechRecognitionBubble::type() != |
| 131 MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED) { | 131 MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED) { |
| 132 test_fixture_->controller_->SetBubbleWarmUpMode(kBubbleSessionId); | 132 test_fixture_->controller_->SetBubbleMessage(ASCIIToUTF16("Test")); |
| 133 } else { | |
| 134 test_fixture_->controller_->SetBubbleMessage(kBubbleSessionId, | |
| 135 ASCIIToUTF16("Test")); | |
| 136 } | 133 } |
| 137 } | 134 } |
| 138 | 135 |
| 139 static SpeechRecognitionBubble* CreateBubble( | 136 static SpeechRecognitionBubble* CreateBubble( |
| 140 WebContents* web_contents, | 137 WebContents* web_contents, |
| 141 SpeechRecognitionBubble::Delegate* delegate, | 138 SpeechRecognitionBubble::Delegate* delegate, |
| 142 const gfx::Rect& element_rect) { | 139 const gfx::Rect& element_rect) { |
| 143 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 140 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 144 // Set up to activate the bubble soon after it gets created, since we test | 141 // Set up to activate the bubble soon after it gets created, since we test |
| 145 // events sent by the bubble and those are handled only when the bubble is | 142 // events sent by the bubble and those are handled only when the bubble is |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // focus changed callback comes back in the IO thread. | 182 // focus changed callback comes back in the IO thread. |
| 186 TEST_F(SpeechRecognitionBubbleControllerTest, TestFocusChanged) { | 183 TEST_F(SpeechRecognitionBubbleControllerTest, TestFocusChanged) { |
| 187 MockSpeechRecognitionBubble::set_type( | 184 MockSpeechRecognitionBubble::set_type( |
| 188 MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED); | 185 MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED); |
| 189 | 186 |
| 190 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); | 187 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); |
| 191 MessageLoop::current()->Run(); | 188 MessageLoop::current()->Run(); |
| 192 EXPECT_TRUE(focus_changed_); | 189 EXPECT_TRUE(focus_changed_); |
| 193 EXPECT_FALSE(cancel_clicked_); | 190 EXPECT_FALSE(cancel_clicked_); |
| 194 EXPECT_FALSE(try_again_clicked_); | 191 EXPECT_FALSE(try_again_clicked_); |
| 195 controller_->CloseBubble(kBubbleSessionId); | 192 controller_->CloseBubble(); |
| 196 } | 193 } |
| 197 | 194 |
| 198 // Test that the speech bubble UI gets created in the UI thread and that the | 195 // Test that the speech bubble UI gets created in the UI thread and that the |
| 199 // recognition cancelled callback comes back in the IO thread. | 196 // recognition cancelled callback comes back in the IO thread. |
| 200 TEST_F(SpeechRecognitionBubbleControllerTest, TestRecognitionCancelled) { | 197 TEST_F(SpeechRecognitionBubbleControllerTest, TestRecognitionCancelled) { |
| 201 MockSpeechRecognitionBubble::set_type( | 198 MockSpeechRecognitionBubble::set_type( |
| 202 MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_CANCEL); | 199 MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_CANCEL); |
| 203 | 200 |
| 204 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); | 201 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); |
| 205 MessageLoop::current()->Run(); | 202 MessageLoop::current()->Run(); |
| 206 EXPECT_TRUE(cancel_clicked_); | 203 EXPECT_TRUE(cancel_clicked_); |
| 207 EXPECT_FALSE(try_again_clicked_); | 204 EXPECT_FALSE(try_again_clicked_); |
| 208 EXPECT_FALSE(focus_changed_); | 205 EXPECT_FALSE(focus_changed_); |
| 209 controller_->CloseBubble(kBubbleSessionId); | 206 controller_->CloseBubble(); |
| 210 } | 207 } |
| 211 | 208 |
| 212 // Test that the speech bubble UI gets created in the UI thread and that the | 209 // Test that the speech bubble UI gets created in the UI thread and that the |
| 213 // try-again button click event comes back in the IO thread. | 210 // try-again button click event comes back in the IO thread. |
| 214 TEST_F(SpeechRecognitionBubbleControllerTest, TestTryAgainClicked) { | 211 TEST_F(SpeechRecognitionBubbleControllerTest, TestTryAgainClicked) { |
| 215 MockSpeechRecognitionBubble::set_type( | 212 MockSpeechRecognitionBubble::set_type( |
| 216 MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_TRY_AGAIN); | 213 MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_TRY_AGAIN); |
| 217 | 214 |
| 218 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); | 215 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); |
| 219 MessageLoop::current()->Run(); | 216 MessageLoop::current()->Run(); |
| 220 EXPECT_FALSE(cancel_clicked_); | 217 EXPECT_FALSE(cancel_clicked_); |
| 221 EXPECT_TRUE(try_again_clicked_); | 218 EXPECT_TRUE(try_again_clicked_); |
| 222 EXPECT_FALSE(focus_changed_); | 219 EXPECT_FALSE(focus_changed_); |
| 223 controller_->CloseBubble(kBubbleSessionId); | 220 controller_->CloseBubble(); |
| 224 } | 221 } |
| 225 | 222 |
| 226 } // namespace speech | 223 } // namespace speech |
| OLD | NEW |