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

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

Issue 2400503002: [Translate] Integrate TranslateEventProto UMA logging into TranslateManager. (Closed)
Patch Set: fix trybots Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/app/chrome_command_ids.h" 19 #include "chrome/app/chrome_command_ids.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/extensions/test_extension_system.h" 21 #include "chrome/browser/extensions/test_extension_system.h"
22 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
23 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 23 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
24 #include "chrome/browser/translate/chrome_translate_client.h" 24 #include "chrome/browser/translate/chrome_translate_client.h"
25 #include "chrome/browser/translate/translate_service.h" 25 #include "chrome/browser/translate/translate_service.h"
26 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 27 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
27 #include "chrome/browser/ui/translate/translate_bubble_model.h" 28 #include "chrome/browser/ui/translate/translate_bubble_model.h"
28 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" 29 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
33 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h" 35 #include "chrome/test/base/testing_profile.h"
35 #include "components/infobars/core/infobar.h" 36 #include "components/infobars/core/infobar.h"
(...skipping 29 matching lines...) Expand all
65 #if !defined(USE_AURA) 66 #if !defined(USE_AURA)
66 #include "components/translate/core/browser/translate_infobar_delegate.h" 67 #include "components/translate/core/browser/translate_infobar_delegate.h"
67 #endif 68 #endif
68 69
69 namespace { 70 namespace {
70 71
71 class MockTranslateBubbleFactory : public TranslateBubbleFactory { 72 class MockTranslateBubbleFactory : public TranslateBubbleFactory {
72 public: 73 public:
73 MockTranslateBubbleFactory() {} 74 MockTranslateBubbleFactory() {}
74 75
75 void ShowImplementation( 76 ShowTranslateBubbleResult ShowImplementation(
76 BrowserWindow* window, 77 BrowserWindow* window,
77 content::WebContents* web_contents, 78 content::WebContents* web_contents,
78 translate::TranslateStep step, 79 translate::TranslateStep step,
79 translate::TranslateErrors::Type error_type) override { 80 translate::TranslateErrors::Type error_type) override {
80 if (model_) { 81 if (model_) {
81 model_->SetViewState( 82 model_->SetViewState(
82 TranslateBubbleModelImpl::TranslateStepToViewState(step)); 83 TranslateBubbleModelImpl::TranslateStepToViewState(step));
83 return; 84 return ShowTranslateBubbleResult::SUCCESS;
84 } 85 }
85 86
86 ChromeTranslateClient* chrome_translate_client = 87 ChromeTranslateClient* chrome_translate_client =
87 ChromeTranslateClient::FromWebContents(web_contents); 88 ChromeTranslateClient::FromWebContents(web_contents);
88 std::string source_language = 89 std::string source_language =
89 chrome_translate_client->GetLanguageState().original_language(); 90 chrome_translate_client->GetLanguageState().original_language();
90 std::string target_language = 91 std::string target_language =
91 translate::TranslateDownloadManager::GetLanguageCode( 92 translate::TranslateDownloadManager::GetLanguageCode(
92 g_browser_process->GetApplicationLocale()); 93 g_browser_process->GetApplicationLocale());
93 94
94 std::unique_ptr<translate::TranslateUIDelegate> ui_delegate( 95 std::unique_ptr<translate::TranslateUIDelegate> ui_delegate(
95 new translate::TranslateUIDelegate( 96 new translate::TranslateUIDelegate(
96 chrome_translate_client->GetTranslateManager()->GetWeakPtr(), 97 chrome_translate_client->GetTranslateManager()->GetWeakPtr(),
97 source_language, target_language)); 98 source_language, target_language));
98 model_.reset(new TranslateBubbleModelImpl(step, std::move(ui_delegate))); 99 model_.reset(new TranslateBubbleModelImpl(step, std::move(ui_delegate)));
100 return ShowTranslateBubbleResult::SUCCESS;
99 } 101 }
100 102
101 bool DismissBubble() { 103 bool DismissBubble() {
102 if (!model_) 104 if (!model_)
103 return false; 105 return false;
104 model_->DeclineTranslation(); 106 model_->DeclineTranslation();
105 model_->OnBubbleClosing(); 107 model_->OnBubbleClosing();
106 model_.reset(); 108 model_.reset();
107 return true; 109 return true;
108 } 110 }
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 1811
1810 // Check the bubble exists instead of the infobar. 1812 // Check the bubble exists instead of the infobar.
1811 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1813 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1812 ASSERT_TRUE(infobar == NULL); 1814 ASSERT_TRUE(infobar == NULL);
1813 TranslateBubbleModel* bubble = factory->model(); 1815 TranslateBubbleModel* bubble = factory->model();
1814 ASSERT_TRUE(bubble != NULL); 1816 ASSERT_TRUE(bubble != NULL);
1815 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, 1817 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING,
1816 bubble->GetViewState()); 1818 bubble->GetViewState());
1817 } 1819 }
1818 #endif // defined(USE_AURA) 1820 #endif // defined(USE_AURA)
OLDNEW
« no previous file with comments | « chrome/browser/translate/chrome_translate_client.cc ('k') | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698