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

Side by Side Diff: content/browser/renderer_host/render_view_host_manager_browsertest.cc

Issue 11343017: Move remaining files in content\browser\renderer_host to content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 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 | Annotate | Revision Log
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/json/json_reader.h" 6 #include "base/json/json_reader.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/common/content_constants_internal.h" 10 #include "content/common/content_constants_internal.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
24 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "content/shell/shell.h" 26 #include "content/shell/shell.h"
27 #include "content/test/content_browser_test.h" 27 #include "content/test/content_browser_test.h"
28 #include "content/test/content_browser_test_utils.h" 28 #include "content/test/content_browser_test_utils.h"
29 #include "net/base/net_util.h" 29 #include "net/base/net_util.h"
30 #include "net/test/test_server.h" 30 #include "net/test/test_server.h"
31 31
32 using content::WebContentsImpl; 32 namespace content {
33
34 namespace { 33 namespace {
35 34
36 bool CompareTrees(base::DictionaryValue* first, base::DictionaryValue* second) { 35 bool CompareTrees(base::DictionaryValue* first, base::DictionaryValue* second) {
37 string16 name1; 36 string16 name1;
38 string16 name2; 37 string16 name2;
39 if (!first->GetString(content::kFrameTreeNodeNameKey, &name1) || 38 if (!first->GetString(kFrameTreeNodeNameKey, &name1) ||
40 !second->GetString(content::kFrameTreeNodeNameKey, &name2)) 39 !second->GetString(kFrameTreeNodeNameKey, &name2))
41 return false; 40 return false;
42 if (name1 != name2) 41 if (name1 != name2)
43 return false; 42 return false;
44 43
45 int id1 = 0; 44 int id1 = 0;
46 int id2 = 0; 45 int id2 = 0;
47 if (!first->GetInteger(content::kFrameTreeNodeIdKey, &id1) || 46 if (!first->GetInteger(kFrameTreeNodeIdKey, &id1) ||
48 !second->GetInteger(content::kFrameTreeNodeIdKey, &id2)) { 47 !second->GetInteger(kFrameTreeNodeIdKey, &id2)) {
49 return false; 48 return false;
50 } 49 }
51 if (id1 != id2) 50 if (id1 != id2)
52 return false; 51 return false;
53 52
54 ListValue* subtree1 = NULL; 53 ListValue* subtree1 = NULL;
55 ListValue* subtree2 = NULL; 54 ListValue* subtree2 = NULL;
56 bool result1 = first->GetList(content::kFrameTreeNodeSubtreeKey, &subtree1); 55 bool result1 = first->GetList(kFrameTreeNodeSubtreeKey, &subtree1);
57 bool result2 = second->GetList(content::kFrameTreeNodeSubtreeKey, &subtree2); 56 bool result2 = second->GetList(kFrameTreeNodeSubtreeKey, &subtree2);
58 if (!result1 && !result2) 57 if (!result1 && !result2)
59 return true; 58 return true;
60 if (!result1 || !result2) 59 if (!result1 || !result2)
61 return false; 60 return false;
62 61
63 if (subtree1->GetSize() != subtree2->GetSize()) 62 if (subtree1->GetSize() != subtree2->GetSize())
64 return false; 63 return false;
65 64
66 base::DictionaryValue* child1 = NULL; 65 base::DictionaryValue* child1 = NULL;
67 base::DictionaryValue* child2 = NULL; 66 base::DictionaryValue* child2 = NULL;
68 for (size_t i = 0; i < subtree1->GetSize(); ++i) { 67 for (size_t i = 0; i < subtree1->GetSize(); ++i) {
69 if (!subtree1->GetDictionary(i, &child1) || 68 if (!subtree1->GetDictionary(i, &child1) ||
70 !subtree2->GetDictionary(i, &child2)) { 69 !subtree2->GetDictionary(i, &child2)) {
71 return false; 70 return false;
72 } 71 }
73 if (!CompareTrees(child1, child2)) 72 if (!CompareTrees(child1, child2))
74 return false; 73 return false;
75 } 74 }
76 75
77 return true; 76 return true;
78 } 77 }
79 78
80 base::DictionaryValue* GetTree(content::RenderViewHostImpl* rvh) { 79 base::DictionaryValue* GetTree(RenderViewHostImpl* rvh) {
81 std::string frame_tree = rvh->frame_tree(); 80 std::string frame_tree = rvh->frame_tree();
82 EXPECT_FALSE(frame_tree.empty()); 81 EXPECT_FALSE(frame_tree.empty());
83 base::Value* v = base::JSONReader::Read(frame_tree); 82 base::Value* v = base::JSONReader::Read(frame_tree);
84 base::DictionaryValue* tree = NULL; 83 base::DictionaryValue* tree = NULL;
85 EXPECT_TRUE(v->IsType(base::Value::TYPE_DICTIONARY)); 84 EXPECT_TRUE(v->IsType(base::Value::TYPE_DICTIONARY));
86 EXPECT_TRUE(v->GetAsDictionary(&tree)); 85 EXPECT_TRUE(v->GetAsDictionary(&tree));
87 return tree; 86 return tree;
88 } 87 }
89 88
90 } // namespace 89 } // namespace
91 90
92 namespace content {
93
94 class RenderViewHostManagerTest : public ContentBrowserTest { 91 class RenderViewHostManagerTest : public ContentBrowserTest {
95 public: 92 public:
96 RenderViewHostManagerTest() {} 93 RenderViewHostManagerTest() {}
97 94
98 static bool GetFilePathWithHostAndPortReplacement( 95 static bool GetFilePathWithHostAndPortReplacement(
99 const std::string& original_file_path, 96 const std::string& original_file_path,
100 const net::HostPortPair& host_port_pair, 97 const net::HostPortPair& host_port_pair,
101 std::string* replacement_path) { 98 std::string* replacement_path) {
102 std::vector<net::TestServer::StringPair> replacement_text; 99 std::vector<net::TestServer::StringPair> replacement_text;
103 replacement_text.push_back( 100 replacement_text.push_back(
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1055
1059 // Observe the created render_view_host's to make sure they will not leak. 1056 // Observe the created render_view_host's to make sure they will not leak.
1060 RenderViewHostObserverArray rvh_observers; 1057 RenderViewHostObserverArray rvh_observers;
1061 1058
1062 GURL navigated_url(test_server()->GetURL("files/title2.html")); 1059 GURL navigated_url(test_server()->GetURL("files/title2.html"));
1063 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + 1060 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") +
1064 navigated_url.spec()); 1061 navigated_url.spec());
1065 1062
1066 // Let's ensure that when we start with a blank window, navigating away to a 1063 // Let's ensure that when we start with a blank window, navigating away to a
1067 // view-source URL, we create a new SiteInstance. 1064 // view-source URL, we create a new SiteInstance.
1068 content::RenderViewHost* blank_rvh = shell()->web_contents()-> 1065 RenderViewHost* blank_rvh = shell()->web_contents()->
1069 GetRenderViewHost(); 1066 GetRenderViewHost();
1070 SiteInstance* blank_site_instance = blank_rvh->GetSiteInstance(); 1067 SiteInstance* blank_site_instance = blank_rvh->GetSiteInstance();
1071 EXPECT_EQ(shell()->web_contents()->GetURL(), GURL::EmptyGURL()); 1068 EXPECT_EQ(shell()->web_contents()->GetURL(), GURL::EmptyGURL());
1072 EXPECT_EQ(blank_site_instance->GetSiteURL(), GURL::EmptyGURL()); 1069 EXPECT_EQ(blank_site_instance->GetSiteURL(), GURL::EmptyGURL());
1073 rvh_observers.AddObserverToRVH(blank_rvh); 1070 rvh_observers.AddObserverToRVH(blank_rvh);
1074 1071
1075 // Now navigate to the view-source URL and ensure we got a different 1072 // Now navigate to the view-source URL and ensure we got a different
1076 // SiteInstance and RenderViewHost. 1073 // SiteInstance and RenderViewHost.
1077 NavigateToURL(shell(), view_source_url); 1074 NavigateToURL(shell(), view_source_url);
1078 EXPECT_NE(blank_rvh, shell()->web_contents()->GetRenderViewHost()); 1075 EXPECT_NE(blank_rvh, shell()->web_contents()->GetRenderViewHost());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 base::DictionaryValue* frames = NULL; 1138 base::DictionaryValue* frames = NULL;
1142 base::ListValue* subtree = NULL; 1139 base::ListValue* subtree = NULL;
1143 1140
1144 // First navigate to a page with no frames and ensure the frame tree has no 1141 // First navigate to a page with no frames and ensure the frame tree has no
1145 // subtrees. 1142 // subtrees.
1146 NavigateToURL(shell(), test_server()->GetURL("files/simple_page.html")); 1143 NavigateToURL(shell(), test_server()->GetURL("files/simple_page.html"));
1147 WebContents* opener_contents = shell()->web_contents(); 1144 WebContents* opener_contents = shell()->web_contents();
1148 RenderViewHostManager* opener_rvhm = static_cast<WebContentsImpl*>( 1145 RenderViewHostManager* opener_rvhm = static_cast<WebContentsImpl*>(
1149 opener_contents)->GetRenderManagerForTesting(); 1146 opener_contents)->GetRenderManagerForTesting();
1150 frames = GetTree(opener_rvhm->current_host()); 1147 frames = GetTree(opener_rvhm->current_host());
1151 EXPECT_FALSE(frames->GetList(content::kFrameTreeNodeSubtreeKey, &subtree)); 1148 EXPECT_FALSE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree));
1152 1149
1153 NavigateToURL(shell(), frame_tree_url); 1150 NavigateToURL(shell(), frame_tree_url);
1154 frames = GetTree(opener_rvhm->current_host()); 1151 frames = GetTree(opener_rvhm->current_host());
1155 EXPECT_TRUE(frames->GetList(content::kFrameTreeNodeSubtreeKey, &subtree)); 1152 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree));
1156 EXPECT_TRUE(subtree->GetSize() == 3); 1153 EXPECT_TRUE(subtree->GetSize() == 3);
1157 1154
1158 scoped_refptr<SiteInstance> orig_site_instance( 1155 scoped_refptr<SiteInstance> orig_site_instance(
1159 opener_contents->GetSiteInstance()); 1156 opener_contents->GetSiteInstance());
1160 EXPECT_TRUE(orig_site_instance != NULL); 1157 EXPECT_TRUE(orig_site_instance != NULL);
1161 1158
1162 ShellAddedObserver shell_observer1; 1159 ShellAddedObserver shell_observer1;
1163 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( 1160 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool(
1164 opener_contents->GetRenderViewHost(), L"", 1161 opener_contents->GetRenderViewHost(), L"",
1165 L"window.domAutomationController.send(openWindow('1-3.html'));", 1162 L"window.domAutomationController.send(openWindow('1-3.html'));",
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 GetTree(opener_rvhm->current_host()), GetTree(rvhm2->current_host()))); 1237 GetTree(opener_rvhm->current_host()), GetTree(rvhm2->current_host())));
1241 1238
1242 // Now let's ensure that using JS to add/remove frames results in proper 1239 // Now let's ensure that using JS to add/remove frames results in proper
1243 // updates. 1240 // updates.
1244 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( 1241 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool(
1245 opener_contents->GetRenderViewHost(), L"", 1242 opener_contents->GetRenderViewHost(), L"",
1246 L"window.domAutomationController.send(removeFrame());", 1243 L"window.domAutomationController.send(removeFrame());",
1247 &success)); 1244 &success));
1248 EXPECT_TRUE(success); 1245 EXPECT_TRUE(success);
1249 frames = GetTree(opener_rvhm->current_host()); 1246 frames = GetTree(opener_rvhm->current_host());
1250 EXPECT_TRUE(frames->GetList(content::kFrameTreeNodeSubtreeKey, &subtree)); 1247 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree));
1251 EXPECT_EQ(subtree->GetSize(), 2U); 1248 EXPECT_EQ(subtree->GetSize(), 2U);
1252 1249
1253 // Create a load observer for the iframe that will be created by the 1250 // Create a load observer for the iframe that will be created by the
1254 // JavaScript code we will execute. 1251 // JavaScript code we will execute.
1255 WindowedNotificationObserver load_observer( 1252 WindowedNotificationObserver load_observer(
1256 NOTIFICATION_LOAD_STOP, 1253 NOTIFICATION_LOAD_STOP,
1257 content::Source<NavigationController>( 1254 Source<NavigationController>(
1258 &opener_contents->GetController())); 1255 &opener_contents->GetController()));
1259 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( 1256 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool(
1260 opener_contents->GetRenderViewHost(), L"", 1257 opener_contents->GetRenderViewHost(), L"",
1261 L"window.domAutomationController.send(addFrame());", 1258 L"window.domAutomationController.send(addFrame());",
1262 &success)); 1259 &success));
1263 EXPECT_TRUE(success); 1260 EXPECT_TRUE(success);
1264 load_observer.Wait(); 1261 load_observer.Wait();
1265 1262
1266 frames = GetTree(opener_rvhm->current_host()); 1263 frames = GetTree(opener_rvhm->current_host());
1267 EXPECT_TRUE(frames->GetList(content::kFrameTreeNodeSubtreeKey, &subtree)); 1264 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree));
1268 EXPECT_EQ(subtree->GetSize(), 3U); 1265 EXPECT_EQ(subtree->GetSize(), 3U);
1269 1266
1270 EXPECT_TRUE(CompareTrees( 1267 EXPECT_TRUE(CompareTrees(
1271 GetTree(opener_rvhm->current_host()), 1268 GetTree(opener_rvhm->current_host()),
1272 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance1)))); 1269 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance1))));
1273 EXPECT_TRUE(CompareTrees( 1270 EXPECT_TRUE(CompareTrees(
1274 GetTree(opener_rvhm->current_host()), 1271 GetTree(opener_rvhm->current_host()),
1275 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance2)))); 1272 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance2))));
1276 } 1273 }
1277 1274
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); 1329 NavigateToURL(shell(), https_server.GetURL("files/title1.html"));
1333 1330
1334 // Make sure it ends up at the right page. 1331 // Make sure it ends up at the right page.
1335 WaitForLoadStop(shell()->web_contents()); 1332 WaitForLoadStop(shell()->web_contents());
1336 EXPECT_EQ(https_server.GetURL("files/title1.html"), 1333 EXPECT_EQ(https_server.GetURL("files/title1.html"),
1337 shell()->web_contents()->GetURL()); 1334 shell()->web_contents()->GetURL());
1338 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); 1335 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance());
1339 } 1336 }
1340 1337
1341 } // namespace content 1338 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_factory.cc ('k') | content/browser/renderer_host/render_view_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698