Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2416)

Unified Diff: chrome/browser/speech/speech_input_bubble_controller_unittest.cc

Issue 6115001: Listen for tab close notifications and cancel active speech sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/speech/speech_input_bubble_controller_unittest.cc
diff --git a/chrome/browser/speech/speech_input_bubble_controller_unittest.cc b/chrome/browser/speech/speech_input_bubble_controller_unittest.cc
index 2ed1f1b8231c8bf1da23b0d7cd37b4b142641387..79f24e1503b5f92e5d8c5e9d25e49a038146c1b5 100644
--- a/chrome/browser/speech/speech_input_bubble_controller_unittest.cc
+++ b/chrome/browser/speech/speech_input_bubble_controller_unittest.cc
@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/speech/speech_input_bubble_controller.h"
+#include "chrome/test/browser_with_test_window_test.h"
+#include "chrome/test/testing_profile.h"
#include "gfx/rect.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -22,7 +25,10 @@ class MockSpeechInputBubble : public SpeechInputBubbleBase {
BUBBLE_TEST_CLICK_TRY_AGAIN,
};
- MockSpeechInputBubble(TabContents*, Delegate* delegate, const gfx::Rect&) {
+ MockSpeechInputBubble(TabContents* tab_contents,
+ Delegate* delegate,
+ const gfx::Rect&)
+ : SpeechInputBubbleBase(tab_contents) {
VLOG(1) << "MockSpeechInputBubble created";
MessageLoop::current()->PostTask(
FROM_HERE, NewRunnableFunction(&InvokeDelegate, delegate));
@@ -62,15 +68,15 @@ class MockSpeechInputBubble : public SpeechInputBubbleBase {
// The test fixture.
class SpeechInputBubbleControllerTest
: public SpeechInputBubbleControllerDelegate,
- public testing::Test {
+ public BrowserWithTestWindowTest {
public:
SpeechInputBubbleControllerTest()
- : io_loop_(MessageLoop::TYPE_IO),
- ui_thread_(BrowserThread::UI), // constructs a new thread and loop
- io_thread_(BrowserThread::IO, &io_loop_), // resuses main thread loop
+ : BrowserWithTestWindowTest(),
+ io_thread_(BrowserThread::IO), // constructs a new thread and loop
cancel_clicked_(false),
try_again_clicked_(false),
focus_changed_(false),
+ bubble_callback_event_(false, false),
bulach 2011/01/07 11:11:29 I'm not very familiar, but seems that BrowserWithT
Satish 2011/01/07 11:19:15 Done.
controller_(ALLOW_THIS_IN_INITIALIZER_LIST(
new SpeechInputBubbleController(this))) {
EXPECT_EQ(NULL, test_fixture_);
@@ -91,26 +97,28 @@ class SpeechInputBubbleControllerTest
} else if (button == SpeechInputBubble::BUTTON_TRY_AGAIN) {
try_again_clicked_ = true;
}
- MessageLoop::current()->Quit();
+ bubble_callback_event_.Signal();
}
virtual void InfoBubbleFocusChanged(int caller_id) {
VLOG(1) << "Received InfoBubbleFocusChanged";
EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
focus_changed_ = true;
- MessageLoop::current()->Quit();
+ bubble_callback_event_.Signal();
}
// testing::Test methods.
virtual void SetUp() {
+ BrowserWithTestWindowTest::SetUp();
SpeechInputBubble::set_factory(
&SpeechInputBubbleControllerTest::CreateBubble);
- ui_thread_.Start();
+ io_thread_.Start();
}
virtual void TearDown() {
SpeechInputBubble::set_factory(NULL);
- ui_thread_.Stop();
+ io_thread_.Stop();
+ BrowserWithTestWindowTest::TearDown();
}
static void ActivateBubble() {
@@ -132,18 +140,24 @@ class SpeechInputBubbleControllerTest
// active.
MessageLoop::current()->PostTask(FROM_HERE,
NewRunnableFunction(&ActivateBubble));
+
+ // The |tab_contents| parameter would be NULL since the dummy caller id
+ // passed to CreateBubble would not have matched any active tab. So get a
+ // real TabContents pointer from the test fixture and pass that, because
+ // the bubble controller registers for tab close notifications which need
+ // a valid TabContents.
+ tab_contents = test_fixture_->browser()->GetSelectedTabContents();
return new MockSpeechInputBubble(tab_contents, delegate, element_rect);
}
protected:
// The main thread of the test is marked as the IO thread and we create a new
// one for the UI thread.
- MessageLoop io_loop_;
- BrowserThread ui_thread_;
BrowserThread io_thread_;
bool cancel_clicked_;
bool try_again_clicked_;
bool focus_changed_;
+ base::WaitableEvent bubble_callback_event_;
scoped_refptr<SpeechInputBubbleController> controller_;
static const int kBubbleCallerId;
@@ -165,7 +179,8 @@ TEST_F(SpeechInputBubbleControllerTest, TestFocusChanged) {
MockSpeechInputBubble::BUBBLE_TEST_FOCUS_CHANGED);
controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1));
- MessageLoop::current()->Run();
+ MessageLoop::current()->RunAllPending();
+ bubble_callback_event_.Wait();
EXPECT_TRUE(focus_changed_);
EXPECT_FALSE(cancel_clicked_);
EXPECT_FALSE(try_again_clicked_);
@@ -179,7 +194,8 @@ TEST_F(SpeechInputBubbleControllerTest, TestRecognitionCancelled) {
MockSpeechInputBubble::BUBBLE_TEST_CLICK_CANCEL);
controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1));
- MessageLoop::current()->Run();
+ MessageLoop::current()->RunAllPending();
+ bubble_callback_event_.Wait();
EXPECT_TRUE(cancel_clicked_);
EXPECT_FALSE(try_again_clicked_);
EXPECT_FALSE(focus_changed_);
@@ -193,7 +209,8 @@ TEST_F(SpeechInputBubbleControllerTest, TestTryAgainClicked) {
MockSpeechInputBubble::BUBBLE_TEST_CLICK_TRY_AGAIN);
controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1));
- MessageLoop::current()->Run();
+ MessageLoop::current()->RunAllPending();
+ bubble_callback_event_.Wait();
EXPECT_FALSE(cancel_clicked_);
EXPECT_TRUE(try_again_clicked_);
EXPECT_FALSE(focus_changed_);
« no previous file with comments | « chrome/browser/speech/speech_input_bubble_controller.cc ('k') | chrome/browser/speech/speech_input_bubble_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698