OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/renderer/chrome_render_frame_observer.h" | 5 #include "chrome/renderer/chrome_render_frame_observer.h" |
6 | 6 |
| 7 #include <tuple> |
| 8 |
7 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 10 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "components/translate/content/common/translate_messages.h" | 11 #include "components/translate/content/common/translate_messages.h" |
10 #include "components/translate/content/renderer/translate_helper.h" | 12 #include "components/translate/content/renderer/translate_helper.h" |
11 #include "components/translate/core/common/translate_constants.h" | 13 #include "components/translate/core/common/translate_constants.h" |
12 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
13 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
14 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
15 | 17 |
16 // Constants for UMA statistic collection. | 18 // Constants for UMA statistic collection. |
17 static const char kTranslateCaptureText[] = "Translate.CaptureText"; | 19 static const char kTranslateCaptureText[] = "Translate.CaptureText"; |
18 | 20 |
19 class ChromeRenderFrameObserverTest : public ChromeRenderViewTest {}; | 21 class ChromeRenderFrameObserverTest : public ChromeRenderViewTest {}; |
20 | 22 |
21 TEST_F(ChromeRenderFrameObserverTest, SkipCapturingSubFrames) { | 23 TEST_F(ChromeRenderFrameObserverTest, SkipCapturingSubFrames) { |
22 base::HistogramTester histogram_tester; | 24 base::HistogramTester histogram_tester; |
23 LoadHTML( | 25 LoadHTML( |
24 "<!DOCTYPE html><body>" | 26 "<!DOCTYPE html><body>" |
25 "This is a main document" | 27 "This is a main document" |
26 "<iframe srcdoc=\"This a document in an iframe.\">" | 28 "<iframe srcdoc=\"This a document in an iframe.\">" |
27 "</body>"); | 29 "</body>"); |
28 view_->GetWebView()->updateAllLifecyclePhases(); | 30 view_->GetWebView()->updateAllLifecyclePhases(); |
29 const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( | 31 const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( |
30 ChromeFrameHostMsg_TranslateLanguageDetermined::ID); | 32 ChromeFrameHostMsg_TranslateLanguageDetermined::ID); |
31 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 33 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
32 ChromeFrameHostMsg_TranslateLanguageDetermined::Param params; | 34 ChromeFrameHostMsg_TranslateLanguageDetermined::Param params; |
33 ChromeFrameHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 35 ChromeFrameHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
34 EXPECT_TRUE(base::get<1>(params)) << "Page should be translatable."; | 36 EXPECT_TRUE(std::get<1>(params)) << "Page should be translatable."; |
35 // Should have 2 samples: one for preliminary capture, one for final capture. | 37 // Should have 2 samples: one for preliminary capture, one for final capture. |
36 // If there are more, then subframes are being captured more than once. | 38 // If there are more, then subframes are being captured more than once. |
37 histogram_tester.ExpectTotalCount(kTranslateCaptureText, 2); | 39 histogram_tester.ExpectTotalCount(kTranslateCaptureText, 2); |
38 } | 40 } |
OLD | NEW |