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