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

Side by Side Diff: chrome/browser/translate/translate_browsertest.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 2013 The Chromium Authors. All rights reserved. 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 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/infobars/infobar.h"
10 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/translate/translate_infobar_delegate.h" 12 #include "chrome/browser/translate/translate_infobar_delegate.h"
12 #include "chrome/browser/translate/translate_script.h" 13 #include "chrome/browser/translate/translate_script.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/test_switches.h" 18 #include "chrome/test/base/test_switches.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 73 }
73 74
74 TranslateInfoBarDelegate* GetExistingTranslateInfoBarDelegate() { 75 TranslateInfoBarDelegate* GetExistingTranslateInfoBarDelegate() {
75 if (!infobar_service_) { 76 if (!infobar_service_) {
76 content::WebContents* web_contents = 77 content::WebContents* web_contents =
77 browser()->tab_strip_model()->GetActiveWebContents(); 78 browser()->tab_strip_model()->GetActiveWebContents();
78 if (web_contents) 79 if (web_contents)
79 infobar_service_ = InfoBarService::FromWebContents(web_contents); 80 infobar_service_ = InfoBarService::FromWebContents(web_contents);
80 } 81 }
81 if (!infobar_service_) { 82 if (!infobar_service_) {
82 EXPECT_TRUE(false) << "infobar service is not available"; 83 ADD_FAILURE() << "infobar service is not available";
83 return NULL; 84 return NULL;
84 } 85 }
85 86
86 TranslateInfoBarDelegate* delegate = NULL; 87 TranslateInfoBarDelegate* delegate = NULL;
87 for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { 88 for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) {
88 // Check if the shown infobar is a confirm infobar coming from the 89 // Check if the shown infobar is a confirm infobar coming from the
89 // |kTranslateSecurityOrigin| flag specified in SetUpCommandLine(). 90 // |kTranslateSecurityOrigin| flag specified in SetUpCommandLine().
90 // This infobar appears in all tests of TranslateBrowserTest and can be 91 // This infobar appears in all tests of TranslateBrowserTest and can be
91 // ignored here. 92 // ignored here.
92 ConfirmInfoBarDelegate* confirm = 93 ConfirmInfoBarDelegate* confirm = infobar_service_->infobar_at(i)->
93 infobar_service_->infobar_at(i)->AsConfirmInfoBarDelegate(); 94 delegate()->AsConfirmInfoBarDelegate();
94 if (confirm) 95 if (confirm)
95 continue; 96 continue;
96 97
97 TranslateInfoBarDelegate* translate = 98 TranslateInfoBarDelegate* translate = infobar_service_->infobar_at(i)->
98 infobar_service_->infobar_at(i)->AsTranslateInfoBarDelegate(); 99 delegate()->AsTranslateInfoBarDelegate();
99 if (translate) { 100 if (translate) {
100 EXPECT_FALSE(delegate) << "multiple infobars are shown unexpectedly"; 101 EXPECT_FALSE(delegate) << "multiple infobars are shown unexpectedly";
101 delegate = translate; 102 delegate = translate;
102 continue; 103 continue;
103 } 104 }
104 105
105 // Other infobar should not be shown. 106 // Other infobar should not be shown.
106 EXPECT_TRUE(delegate); 107 EXPECT_TRUE(delegate);
107 } 108 }
108 return delegate; 109 return delegate;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); 350 GetNonSecureURL(kUpdateLocationAtOnloadTestPath));
350 351
351 // Wait for the page title is changed after the test finished. 352 // Wait for the page title is changed after the test finished.
352 const string16 result = watcher.WaitAndGetTitle(); 353 const string16 result = watcher.WaitAndGetTitle();
353 EXPECT_EQ("PASS", UTF16ToASCII(result)); 354 EXPECT_EQ("PASS", UTF16ToASCII(result));
354 355
355 // Check if there is no Translate infobar. 356 // Check if there is no Translate infobar.
356 translate = GetExistingTranslateInfoBarDelegate(); 357 translate = GetExistingTranslateInfoBarDelegate();
357 EXPECT_FALSE(translate); 358 EXPECT_FALSE(translate);
358 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698