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

Side by Side Diff: chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc

Issue 148343008: Speech Recognition API: Safeguarding against page closes during startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/speech/speech_recognition_bubble_controller.h" 8 #include "chrome/browser/speech/speech_recognition_bubble_controller.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h"
14 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
17 19
20
18 using content::BrowserThread; 21 using content::BrowserThread;
19 using content::WebContents; 22 using content::WebContents;
20 23
21 namespace speech { 24 namespace speech {
22 25
23 // A mock bubble class which fakes a focus change or recognition cancel by the 26 // A mock bubble class which fakes a focus change or recognition cancel by the
24 // user and closing of the info bubble. 27 // user and closing of the info bubble.
25 class MockSpeechRecognitionBubble : public SpeechRecognitionBubbleBase { 28 class MockSpeechRecognitionBubble : public SpeechRecognitionBubbleBase {
26 public: 29 public:
27 enum BubbleType { 30 enum BubbleType {
28 BUBBLE_TEST_FOCUS_CHANGED, 31 BUBBLE_TEST_FOCUS_CHANGED,
29 BUBBLE_TEST_CLICK_CANCEL, 32 BUBBLE_TEST_CLICK_CANCEL,
30 BUBBLE_TEST_CLICK_TRY_AGAIN, 33 BUBBLE_TEST_CLICK_TRY_AGAIN,
31 }; 34 };
32 35
33 MockSpeechRecognitionBubble(WebContents* web_contents, 36 MockSpeechRecognitionBubble(int render_process_id, int render_view_id,
34 Delegate* delegate, 37 Delegate* delegate, const gfx::Rect&)
35 const gfx::Rect&) 38 : SpeechRecognitionBubbleBase(render_process_id, render_view_id) {
36 : SpeechRecognitionBubbleBase(web_contents) {
37 VLOG(1) << "MockSpeechRecognitionBubble created"; 39 VLOG(1) << "MockSpeechRecognitionBubble created";
38 base::MessageLoop::current()->PostTask( 40 base::MessageLoop::current()->PostTask(
39 FROM_HERE, base::Bind(&InvokeDelegate, delegate)); 41 FROM_HERE, base::Bind(&InvokeDelegate, delegate));
40 } 42 }
41 43
42 static void InvokeDelegate(Delegate* delegate) { 44 static void InvokeDelegate(Delegate* delegate) {
43 VLOG(1) << "MockSpeechRecognitionBubble invoking delegate for type " 45 VLOG(1) << "MockSpeechRecognitionBubble invoking delegate for type "
44 << type_; 46 << type_;
45 switch (type_) { 47 switch (type_) {
46 case BUBBLE_TEST_FOCUS_CHANGED: 48 case BUBBLE_TEST_FOCUS_CHANGED:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 WebContents* web_contents, 136 WebContents* web_contents,
135 SpeechRecognitionBubble::Delegate* delegate, 137 SpeechRecognitionBubble::Delegate* delegate,
136 const gfx::Rect& element_rect) { 138 const gfx::Rect& element_rect) {
137 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 139 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
138 // Set up to activate the bubble soon after it gets created, since we test 140 // Set up to activate the bubble soon after it gets created, since we test
139 // events sent by the bubble and those are handled only when the bubble is 141 // events sent by the bubble and those are handled only when the bubble is
140 // active. 142 // active.
141 base::MessageLoop::current()->PostTask(FROM_HERE, 143 base::MessageLoop::current()->PostTask(FROM_HERE,
142 base::Bind(&ActivateBubble)); 144 base::Bind(&ActivateBubble));
143 145
144 // The |web_contents| parameter would be NULL since the dummy session id 146 return new MockSpeechRecognitionBubble(0, 0, delegate, element_rect);
145 // passed to CreateBubble would not have matched any active tab. So get a
146 // real WebContents pointer from the test fixture and pass that, because
147 // the bubble controller registers for tab close notifications which need
148 // a valid WebContents.
149 web_contents =
150 test_fixture_->browser()->tab_strip_model()->GetActiveWebContents();
151 return new MockSpeechRecognitionBubble(web_contents, delegate,
152 element_rect);
153 } 147 }
154 148
155 protected: 149 protected:
156 bool cancel_clicked_; 150 bool cancel_clicked_;
157 bool try_again_clicked_; 151 bool try_again_clicked_;
158 bool focus_changed_; 152 bool focus_changed_;
159 scoped_refptr<SpeechRecognitionBubbleController> controller_; 153 scoped_refptr<SpeechRecognitionBubbleController> controller_;
160 154
161 static const int kBubbleSessionId; 155 static const int kBubbleSessionId;
162 static SpeechRecognitionBubbleControllerTest* test_fixture_; 156 static SpeechRecognitionBubbleControllerTest* test_fixture_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 200
207 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); 201 controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1));
208 base::RunLoop().RunUntilIdle(); 202 base::RunLoop().RunUntilIdle();
209 EXPECT_FALSE(cancel_clicked_); 203 EXPECT_FALSE(cancel_clicked_);
210 EXPECT_TRUE(try_again_clicked_); 204 EXPECT_TRUE(try_again_clicked_);
211 EXPECT_FALSE(focus_changed_); 205 EXPECT_FALSE(focus_changed_);
212 controller_->CloseBubble(); 206 controller_->CloseBubble();
213 } 207 }
214 208
215 } // namespace speech 209 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698