OLD | NEW |
---|---|
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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 7904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7915 | 7915 |
7916 // Now go forward three entries from the child1 frame and check that the | 7916 // Now go forward three entries from the child1 frame and check that the |
7917 // history length and offset are not stale in b.com. | 7917 // history length and offset are not stale in b.com. |
7918 EXPECT_TRUE(ExecuteScript(child1, "history.go(3);")); | 7918 EXPECT_TRUE(ExecuteScript(child1, "history.go(3);")); |
7919 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 7919 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
7920 EXPECT_EQ(main_url, root->current_url()); | 7920 EXPECT_EQ(main_url, root->current_url()); |
7921 EXPECT_EQ(child1_last_url, child1->current_url()); | 7921 EXPECT_EQ(child1_last_url, child1->current_url()); |
7922 EXPECT_EQ(child2_last_url, child2->current_url()); | 7922 EXPECT_EQ(child2_last_url, child2->current_url()); |
7923 } | 7923 } |
7924 | 7924 |
7925 #if defined(OS_MACOSX) | |
7926 class TextInputClientMacHelper { | |
7927 public: | |
7928 TextInputClientMacHelper() {} | |
7929 ~TextInputClientMacHelper() {} | |
7930 | |
7931 void WaitForStringFromRange(RenderWidgetHost* rwh, const gfx::Range& range) { | |
7932 GetStringFromRangeForRenderWidget( | |
7933 rwh, range, base::Bind(&TextInputClientMacHelper::OnResult, | |
7934 base::Unretained(this))); | |
7935 loop_runner_ = new MessageLoopRunner(); | |
7936 loop_runner_->Run(); | |
7937 } | |
7938 | |
7939 void WaitForStringAtPoint(RenderWidgetHost* rwh, const gfx::Point& point) { | |
7940 GetStringAtPointForRenderWidget( | |
7941 rwh, point, base::Bind(&TextInputClientMacHelper::OnResult, | |
7942 base::Unretained(this))); | |
erikchen
2016/09/01 00:04:29
why don't you need to run the RunLoop here? If tha
EhsanK
2016/09/01 21:58:37
I should have used the loop. Fails without it sinc
| |
7943 } | |
7944 const std::string& word() const { return word_; } | |
7945 const gfx::Point& point() const { return point_; } | |
7946 | |
7947 private: | |
7948 void OnResult(const std::string& string, const gfx::Point& point) { | |
7949 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
7950 BrowserThread::PostTask( | |
7951 BrowserThread::UI, FROM_HERE, | |
7952 base::Bind(&TextInputClientMacHelper::OnResult, | |
7953 base::Unretained(this), string, point)); | |
7954 return; | |
7955 } | |
7956 word_ = string; | |
7957 point_ = point; | |
7958 | |
7959 if (loop_runner_ && loop_runner_->loop_running()) | |
7960 loop_runner_->Quit(); | |
7961 } | |
7962 | |
7963 std::string word_; | |
7964 gfx::Point point_; | |
7965 scoped_refptr<MessageLoopRunner> loop_runner_; | |
7966 | |
7967 DISALLOW_COPY_AND_ASSIGN(TextInputClientMacHelper); | |
7968 }; | |
7969 | |
7970 void SetDocumentBodyHTML(FrameTreeNode* node, const std::string& html) { | |
erikchen
2016/09/01 00:04:29
This should be in an anonymous namespace?
EhsanK
2016/09/01 21:58:37
Actually I do not need this method anymore. Sorry
| |
7971 EXPECT_TRUE(ExecuteScript( | |
7972 node, | |
7973 base::StringPrintf("document.body.innerHTML = '%s';", html.c_str()))); | |
7974 } | |
7975 | |
7976 // Tests related to TextInputClientMac. | |
7977 class SitePerProcessTextInputClientMacTest : public SitePerProcessBrowserTest { | |
7978 }; | |
7979 | |
7980 // This test will load a text only page inside a child frame and then queries | |
7981 // the | |
Charlie Reis
2016/08/31 22:50:03
nit: Fix line wrap.
EhsanK
2016/09/01 21:58:37
Done. When I get a chance I will take a look at 'g
| |
7982 // string range which includes the first word. Then it uses the returned point | |
7983 // to query the text again and verifies that correct result is returned. | |
7984 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, | |
7985 GetStringFromRangeAndPointChildFrame) { | |
7986 GURL main_url(embedded_test_server()->GetURL( | |
7987 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
7988 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
7989 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
7990 FrameTreeNode* child = root->child_at(0); | |
7991 NavigateFrameToURL(child, | |
7992 embedded_test_server()->GetURL("b.com", "/title1.html")); | |
7993 | |
7994 RenderWidgetHost* child_widget_host = | |
7995 child->current_frame_host()->GetRenderWidgetHost(); | |
7996 TextInputClientMacHelper helper; | |
7997 | |
7998 // Get string from range. | |
7999 helper.WaitForStringFromRange(child_widget_host, gfx::Range(0, 5)); | |
8000 gfx::Point point = helper.point(); | |
8001 std::string word = helper.word(); | |
erikchen
2016/09/01 00:04:29
can you add an expectation that verifies the conte
EhsanK
2016/09/01 21:58:37
Done. Thanks! (the word to be verified is "This").
| |
8002 | |
8003 // Now get it at a given point. | |
8004 point.SetPoint(point.x(), | |
8005 child_widget_host->GetView()->GetViewBounds().size().height() - | |
8006 point.y()); | |
8007 helper.WaitForStringAtPoint(child_widget_host, point); | |
8008 EXPECT_EQ(word, helper.word()); | |
8009 } | |
8010 | |
8011 // This test will load a text only page and then queries the string range which | |
8012 // includes the first word. Then it uses the returned point to query the text | |
8013 // again and verifies that correct result is returned. | |
8014 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, | |
8015 GetStringFromRangeAndPointMainFrame) { | |
8016 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
8017 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
8018 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
8019 RenderWidgetHost* widget_host = | |
8020 root->current_frame_host()->GetRenderWidgetHost(); | |
8021 TextInputClientMacHelper helper; | |
8022 | |
8023 // Get string from range. | |
8024 helper.WaitForStringFromRange(widget_host, gfx::Range(0, 5)); | |
8025 gfx::Point point = helper.point(); | |
8026 std::string word = helper.word(); | |
8027 | |
8028 // Now get it at a given point. | |
8029 point.SetPoint( | |
8030 point.x(), | |
8031 widget_host->GetView()->GetViewBounds().size().height() - point.y()); | |
8032 helper.WaitForStringAtPoint(widget_host, point); | |
8033 EXPECT_EQ(word, helper.word()); | |
8034 } | |
8035 | |
8036 #endif | |
erikchen
2016/09/01 00:04:29
s/#endif/#endif // defined(OS_MACOSX)
EhsanK
2016/09/01 21:58:37
Done.
| |
8037 | |
7925 } // namespace content | 8038 } // namespace content |
OLD | NEW |