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

Unified Diff: chrome/browser/cocoa/translate/translate_infobar_unittest.mm

Issue 2815013: Refactor the translate infobars on mac to match the new windows code. (Closed)
Patch Set: Move unittest stuff back to class files Created 10 years, 6 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/cocoa/translate/translate_infobar_unittest.mm
diff --git a/chrome/browser/cocoa/translate_infobar_unittest.mm b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
similarity index 55%
rename from chrome/browser/cocoa/translate_infobar_unittest.mm
rename to chrome/browser/cocoa/translate/translate_infobar_unittest.mm
index 07e4185d29a614026de0ad1b737c2436c04a5630..38eb1ace160576b2f9c57a536d1ae0a6b3aa427e 100644
--- a/chrome/browser/cocoa/translate_infobar_unittest.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
@@ -3,30 +3,44 @@
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
-#import "chrome/browser/cocoa/translate_infobar.h"
-#include "base/scoped_nsobject.h"
-#include "base/string_util.h"
-#include "chrome/app/chrome_dll_resource.h" // For translate menu command ids.
+#import "base/scoped_nsobject.h"
+#import "base/string_util.h"
+#import "chrome/app/chrome_dll_resource.h" // For translate menu command ids.
+#import "chrome/browser/cocoa/browser_test_helper.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
-#include "chrome/browser/translate/translate_infobars_delegates.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
+#import "chrome/browser/cocoa/infobar.h"
+#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
+#import "chrome/browser/cocoa/translate/before_translate_infobar_controller.h"
+#import "chrome/browser/cocoa/translate/after_translate_infobar_controller.h"
+#import "chrome/browser/cocoa/translate/translate_message_infobar_controller.h"
+#import "chrome/browser/renderer_host/site_instance.h"
+#import "chrome/browser/tab_contents/tab_contents.h"
+#import "chrome/browser/translate/translate_infobar_delegate2.h"
+#import "ipc/ipc_channel.h"
+#import "testing/gmock/include/gmock/gmock.h"
+#import "testing/gtest/include/gtest/gtest.h"
+#import "testing/platform_test.h"
namespace {
// All states the translate toolbar can assume.
-TranslateInfoBarDelegate::TranslateState kTranslateToolbarStates[] = {
- TranslateInfoBarDelegate::kBeforeTranslate,
- TranslateInfoBarDelegate::kAfterTranslate,
- TranslateInfoBarDelegate::kTranslateError};
+TranslateInfoBarDelegate2::Type kTranslateToolbarStates[] = {
+ TranslateInfoBarDelegate2::BEFORE_TRANSLATE,
+ TranslateInfoBarDelegate2::AFTER_TRANSLATE,
+ TranslateInfoBarDelegate2::TRANSLATING,
+ TranslateInfoBarDelegate2::TRANSLATION_ERROR
+};
-class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate {
+class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate2 {
public:
- MockTranslateInfoBarDelegate() {
+ MockTranslateInfoBarDelegate(TranslateInfoBarDelegate2::Type type,
+ TranslateErrors::Type error,
+ TabContents* contents)
+ : TranslateInfoBarDelegate2(type, error, contents, "en", "es"){
// Start out in the "Before Translate" state.
- UpdateState(kBeforeTranslate, TranslateErrors::NONE);
+ type_ = type;
+
}
virtual string16 GetDisplayNameForLocale(const std::string& language_code) {
@@ -51,45 +65,57 @@ class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate {
MOCK_METHOD0(ToggleLanguageBlacklist, void());
MOCK_METHOD0(ToggleSiteBlacklist, void());
MOCK_METHOD0(ToggleAlwaysTranslate, void());
-
};
-class TranslationBarInfoTest : public CocoaTest {
+class TranslationInfoBarTest : public CocoaTest {
public:
scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate;
- scoped_nsobject<TranslateInfoBarController> infobar_controller;
+ scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller;
+ BrowserTestHelper browser_helper_;
public:
// Each test gets a single Mock translate delegate for the lifetime of
// the test.
virtual void SetUp() {
CocoaTest::SetUp();
- infobar_delegate.reset(new MockTranslateInfoBarDelegate);
+ CreateInfoBar();
}
void CreateInfoBar() {
- CreateInfoBar(TranslateInfoBarDelegate::kBeforeTranslate);
+ CreateInfoBar(TranslateInfoBarDelegate2::BEFORE_TRANSLATE);
}
- void CreateInfoBar(TranslateInfoBarDelegate::TranslateState initial_state) {
- infobar_delegate->UpdateState(initial_state, TranslateErrors::NONE);
+ void CreateInfoBar(TranslateInfoBarDelegate2::Type type) {
+ SiteInstance* instance =
+ SiteInstance::CreateSiteInstance(browser_helper_.profile());
+ scoped_ptr<TabContents> tab_contents(
+ new TabContents(browser_helper_.profile(),
+ instance,
+ MSG_ROUTING_NONE,
+ NULL));
+ TranslateErrors::Type error = TranslateErrors::NONE;
+ if (type == TranslateInfoBarDelegate2::TRANSLATION_ERROR)
+ error = TranslateErrors::NETWORK;
+ infobar_delegate.reset(
+ new MockTranslateInfoBarDelegate(type, error, tab_contents.get()));
[[infobar_controller view] removeFromSuperview];
+ scoped_ptr<InfoBar> infobar(infobar_delegate->CreateInfoBar());
infobar_controller.reset(
- [[TranslateInfoBarController alloc]
- initWithDelegate:infobar_delegate.get()]);
+ reinterpret_cast<TranslateInfoBarControllerBase*>(
+ infobar->controller()));
// Need to call this to get the view to load from nib.
[[test_window() contentView] addSubview:[infobar_controller view]];
}
};
// Check that we can instantiate a Translate Infobar correctly.
-TEST_F(TranslationBarInfoTest, Instantiate) {
+TEST_F(TranslationInfoBarTest, Instantiate) {
CreateInfoBar();
ASSERT_TRUE(infobar_controller.get());
}
// Check that clicking the Translate button calls Translate().
-TEST_F(TranslationBarInfoTest, TranslateCalledOnButtonPress) {
+TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) {
CreateInfoBar();
EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
@@ -98,68 +124,26 @@ TEST_F(TranslationBarInfoTest, TranslateCalledOnButtonPress) {
// Check that clicking the "Retry" button calls Translate() when we're
// in the error mode - http://crbug.com/41315 .
-TEST_F(TranslationBarInfoTest, TranslateCalledInErrorMode) {
- CreateInfoBar();
+TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) {
+ CreateInfoBar(TranslateInfoBarDelegate2::TRANSLATION_ERROR);
EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
- infobar_delegate->UpdateState(TranslateInfoBarDelegate::kTranslateError,
- TranslateErrors::NONE);
[infobar_controller ok:nil];
}
// Check that clicking the "Show Original button calls RevertTranslation().
-TEST_F(TranslationBarInfoTest, RevertCalledOnButtonPress) {
+TEST_F(TranslationInfoBarTest, RevertCalledOnButtonPress) {
CreateInfoBar();
EXPECT_CALL(*infobar_delegate, RevertTranslation()).Times(1);
[infobar_controller showOriginal:nil];
}
-// Check that UI is layed out correctly as we transition synchronously through
-// toolbar states.
-TEST_F(TranslationBarInfoTest, StateTransitions) {
- EXPECT_CALL(*infobar_delegate, Translate())
- .Times(0);
- CreateInfoBar();
-
- for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) {
- TranslateInfoBarDelegate::TranslateState state = kTranslateToolbarStates[i];
- TranslateErrors::Type error = TranslateErrors::NONE;
-
- infobar_delegate->UpdateState(state, error);
-
- // Pending Translation == false.
- if (i != 0) {
- // First time around, the toolbar should already be layed out.
- [infobar_controller updateState:state
- translationPending:false
- error:error];
- }
-
- bool result =
- [infobar_controller verifyLayout:state
- translationPending:false];
- EXPECT_TRUE(result) << "Layout wrong, for state " << state <<
- "translatePending=false";
-
- // Pending Translation == true.
- [infobar_controller updateState:state
- translationPending:true
- error:error];
-
- result = [infobar_controller verifyLayout:state translationPending:true];
- EXPECT_TRUE(result) << "Layout wrong, for state " << state <<
- "translatePending=true";
-
- }
-}
-
// Check that items in the options menu are hooked up correctly.
-TEST_F(TranslationBarInfoTest, OptionsMenuItemsHookedUp) {
+TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) {
EXPECT_CALL(*infobar_delegate, Translate())
.Times(0);
- CreateInfoBar();
[infobar_controller rebuildOptionsMenu];
NSMenu* optionsMenu = [infobar_controller optionsMenu];
@@ -181,19 +165,19 @@ TEST_F(TranslationBarInfoTest, OptionsMenuItemsHookedUp) {
{
EXPECT_CALL(*infobar_delegate, ToggleAlwaysTranslate())
.Times(1);
- [infobar_controller menuItemSelected:alwaysTranslateLanguateItem];
+ [infobar_controller optionsMenuChanged:alwaysTranslateLanguateItem];
}
{
EXPECT_CALL(*infobar_delegate, ToggleLanguageBlacklist())
.Times(1);
- [infobar_controller menuItemSelected:neverTranslateLanguateItem];
+ [infobar_controller optionsMenuChanged:neverTranslateLanguateItem];
}
{
EXPECT_CALL(*infobar_delegate, ToggleSiteBlacklist())
.Times(1);
- [infobar_controller menuItemSelected:neverTranslateSiteItem];
+ [infobar_controller optionsMenuChanged:neverTranslateSiteItem];
}
{
@@ -205,32 +189,28 @@ TEST_F(TranslationBarInfoTest, OptionsMenuItemsHookedUp) {
// Check that selecting a new item from the "Source Language" popup in "before
// translate" mode doesn't trigger a translation or change state.
// http://crbug.com/36666
-TEST_F(TranslationBarInfoTest, Bug36666) {
+TEST_F(TranslationInfoBarTest, Bug36666) {
EXPECT_CALL(*infobar_delegate, Translate())
.Times(0);
CreateInfoBar();
int arbitrary_index = 2;
[infobar_controller sourceLanguageModified:arbitrary_index];
- EXPECT_EQ(infobar_delegate->state(),
- TranslateInfoBarDelegate::kBeforeTranslate);
- EXPECT_EQ([infobar_controller state],
- TranslateInfoBarDelegate::kBeforeTranslate);
+ EXPECT_CALL(*infobar_delegate, Translate())
+ .Times(0);
}
// Check that the infobar lays itself out correctly when instantiated in
// each of the states.
// http://crbug.com/36895
-TEST_F(TranslationBarInfoTest, Bug36895) {
+TEST_F(TranslationInfoBarTest, Bug36895) {
EXPECT_CALL(*infobar_delegate, Translate())
.Times(0);
for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) {
CreateInfoBar(kTranslateToolbarStates[i]);
EXPECT_TRUE(
- [infobar_controller verifyLayout:kTranslateToolbarStates[i]
- translationPending:false]) <<
- "Layout wrong, for state #" << i;
+ [infobar_controller verifyLayout]) << "Layout wrong, for state #" << i;
}
}

Powered by Google App Engine
This is Rietveld 408576698