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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 2250183002: New Public IdFromWebContents method on TabManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nit Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <limits.h> 5 #include <limits.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 } 1353 }
1354 1354
1355 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 1355 TabStripModel* tab_strip_model = browser()->tab_strip_model();
1356 1356
1357 // Creates Tab object to ensure the property is correct for the extension. 1357 // Creates Tab object to ensure the property is correct for the extension.
1358 std::unique_ptr<api::tabs::Tab> tab_object_a = 1358 std::unique_ptr<api::tabs::Tab> tab_object_a =
1359 ExtensionTabUtil::CreateTabObject(web_contents_a, tab_strip_model, 0); 1359 ExtensionTabUtil::CreateTabObject(web_contents_a, tab_strip_model, 0);
1360 EXPECT_FALSE(tab_object_a->discarded); 1360 EXPECT_FALSE(tab_object_a->discarded);
1361 1361
1362 // Discards one tab. 1362 // Discards one tab.
1363 EXPECT_TRUE( 1363 EXPECT_TRUE(tab_manager->DiscardTabById(
1364 tab_manager->DiscardTabById(reinterpret_cast<int64_t>(web_contents_a))); 1364 memory::TabManager::IdFromWebContents(web_contents_a)));
Devlin 2016/08/16 22:56:06 We could make this even easier by providing a Disc
Anderson Silva 2016/08/16 23:13:31 Done. You're right, I've even already implemented
1365 web_contents_a = tab_strip_model->GetWebContentsAt(1); 1365 web_contents_a = tab_strip_model->GetWebContentsAt(1);
1366 1366
1367 // Make sure the property is changed accordingly after discarding the tab. 1367 // Make sure the property is changed accordingly after discarding the tab.
1368 tab_object_a = 1368 tab_object_a =
1369 ExtensionTabUtil::CreateTabObject(web_contents_a, tab_strip_model, 0); 1369 ExtensionTabUtil::CreateTabObject(web_contents_a, tab_strip_model, 0);
1370 EXPECT_TRUE(tab_object_a->discarded); 1370 EXPECT_TRUE(tab_object_a->discarded);
1371 1371
1372 // Get non-discarded tabs after discarding one tab. 1372 // Get non-discarded tabs after discarding one tab.
1373 { 1373 {
1374 std::unique_ptr<base::ListValue> result( 1374 std::unique_ptr<base::ListValue> result(
(...skipping 12 matching lines...) Expand all
1387 1387
1388 int id = -1; 1388 int id = -1;
1389 base::Value* tab = nullptr; 1389 base::Value* tab = nullptr;
1390 EXPECT_TRUE(result->Get(0, &tab)); 1390 EXPECT_TRUE(result->Get(0, &tab));
1391 utils::ToDictionary(tab)->GetInteger(keys::kIdKey, &id); 1391 utils::ToDictionary(tab)->GetInteger(keys::kIdKey, &id);
1392 1392
1393 EXPECT_EQ(tab_id_a, id); 1393 EXPECT_EQ(tab_id_a, id);
1394 } 1394 }
1395 1395
1396 // Discards another created tab. 1396 // Discards another created tab.
1397 EXPECT_TRUE( 1397 EXPECT_TRUE(tab_manager->DiscardTabById(
1398 tab_manager->DiscardTabById(reinterpret_cast<int64_t>(web_contents_b))); 1398 memory::TabManager::IdFromWebContents(web_contents_b)));
1399 1399
1400 // Get non-discarded tabs after discarding two created tabs. 1400 // Get non-discarded tabs after discarding two created tabs.
1401 { 1401 {
1402 std::unique_ptr<base::ListValue> result( 1402 std::unique_ptr<base::ListValue> result(
1403 RunQueryFunction("[{\"discarded\": false}]")); 1403 RunQueryFunction("[{\"discarded\": false}]"));
1404 EXPECT_EQ(1u, result->GetSize()); 1404 EXPECT_EQ(1u, result->GetSize());
1405 1405
1406 // Make sure the returned tab is the correct one. 1406 // Make sure the returned tab is the correct one.
1407 int tab_id_c = 1407 int tab_id_c =
1408 ExtensionTabUtil::GetTabId(tab_strip_model->GetWebContentsAt(0)); 1408 ExtensionTabUtil::GetTabId(tab_strip_model->GetWebContentsAt(0));
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 EXPECT_TRUE( 2114 EXPECT_TRUE(
2115 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 2115 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
2116 2116
2117 // chrome.tabs.setZoomSettings(). 2117 // chrome.tabs.setZoomSettings().
2118 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); 2118 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab");
2119 EXPECT_TRUE( 2119 EXPECT_TRUE(
2120 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 2120 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
2121 } 2121 }
2122 2122
2123 } // namespace extensions 2123 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698