Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Side by Side Diff: chrome/browser/browser_browsertest.cc

Issue 1026005: Makes pinned tab restore on startup if you haven't enabled session (Closed)
Patch Set: check Created 10 years, 9 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 | « chrome/browser/browser.cc ('k') | chrome/browser/browser_init.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <string> 5 #include <string>
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/app_modal_dialog.h" 10 #include "chrome/browser/app_modal_dialog.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_init.h"
13 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/defaults.h" 15 #include "chrome/browser/defaults.h"
14 #include "chrome/browser/extensions/extension_browsertest.h" 16 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
16 #include "chrome/browser/js_modal_dialog.h" 18 #include "chrome/browser/js_modal_dialog.h"
17 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
18 #include "chrome/browser/renderer_host/render_process_host.h" 20 #include "chrome/browser/renderer_host/render_process_host.h"
19 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/browser/tabs/pinned_tab_codec.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
24 #include "chrome/common/page_transition_types.h" 27 #include "chrome/common/page_transition_types.h"
25 #include "chrome/test/in_process_browser_test.h" 28 #include "chrome/test/in_process_browser_test.h"
26 #include "chrome/test/ui_test_utils.h" 29 #include "chrome/test/ui_test_utils.h"
27 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
29 #include "net/base/mock_host_resolver.h" 32 #include "net/base/mock_host_resolver.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 model->CloseTabContentsAt(0); 113 model->CloseTabContentsAt(0);
111 114
112 // There should still be two tabs. 115 // There should still be two tabs.
113 ASSERT_EQ(2, browser()->tab_count()); 116 ASSERT_EQ(2, browser()->tab_count());
114 // The first tab should be a phantom. 117 // The first tab should be a phantom.
115 EXPECT_TRUE(model->IsPhantomTab(0)); 118 EXPECT_TRUE(model->IsPhantomTab(0));
116 // And the tab contents of the first tab should have changed. 119 // And the tab contents of the first tab should have changed.
117 EXPECT_TRUE(model->GetTabContentsAt(0) != app_contents); 120 EXPECT_TRUE(model->GetTabContentsAt(0) != app_contents);
118 } 121 }
119 122
120
121 protected: 123 protected:
122 virtual void SetUpCommandLine(CommandLine* command_line) { 124 virtual void SetUpCommandLine(CommandLine* command_line) {
123 ExtensionBrowserTest::SetUpCommandLine(command_line); 125 ExtensionBrowserTest::SetUpCommandLine(command_line);
124 126
125 // Needed for phantom tab tests. 127 // Needed for phantom tab tests.
126 command_line->AppendSwitch(switches::kEnableExtensionApps); 128 command_line->AppendSwitch(switches::kEnableExtensionApps);
127 } 129 }
128 130
129 // In RTL locales wrap the page title with RTL embedding characters so that it 131 // In RTL locales wrap the page title with RTL embedding characters so that it
130 // matches the value returned by GetWindowTitle(). 132 // matches the value returned by GetWindowTitle().
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 EXPECT_EQ("en", current_tab->language_state().original_language()); 452 EXPECT_EQ("en", current_tab->language_state().original_language());
451 453
452 // Now navigate to a page in French. 454 // Now navigate to a page in French.
453 ui_test_utils::NavigateToURL( 455 ui_test_utils::NavigateToURL(
454 browser(), GURL(server->TestServerPage("files/french_page.html"))); 456 browser(), GURL(server->TestServerPage("files/french_page.html")));
455 EXPECT_TRUE(current_tab->language_state().original_language().empty()); 457 EXPECT_TRUE(current_tab->language_state().original_language().empty());
456 lang = ui_test_utils::WaitForLanguageDetection(current_tab); 458 lang = ui_test_utils::WaitForLanguageDetection(current_tab);
457 EXPECT_EQ("fr", lang); 459 EXPECT_EQ("fr", lang);
458 EXPECT_EQ("fr", current_tab->language_state().original_language()); 460 EXPECT_EQ("fr", current_tab->language_state().original_language());
459 } 461 }
462
463 // Makes sure pinned tabs are restored correctly on start.
464 IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) {
465 HTTPTestServer* server = StartHTTPServer();
466 ASSERT_TRUE(server);
467
468 // Add an pinned app tab.
469 host_resolver()->AddRule("www.example.com", "127.0.0.1");
470 GURL url(server->TestServerPage("empty.html"));
471 TabStripModel* model = browser()->tabstrip_model();
472 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/")));
473 Extension* app_extension = GetExtension();
474 ui_test_utils::NavigateToURL(browser(), url);
475 TabContents* app_contents = new TabContents(browser()->profile(), NULL,
476 MSG_ROUTING_NONE, NULL);
477 app_contents->SetAppExtension(app_extension);
478 model->AddTabContents(app_contents, 0, false, 0, false);
479 model->SetTabPinned(0, true);
480 ui_test_utils::NavigateToURL(browser(), url);
481
482 // Add a non pinned tab.
483 browser()->NewTab();
484
485 // Add a pinned non-app tab.
486 browser()->NewTab();
487 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
488 model->SetTabPinned(2, true);
489
490 // Write out the pinned tabs.
491 PinnedTabCodec::WritePinnedTabs(browser()->profile());
492
493 // Simulate launching again.
494 CommandLine dummy(CommandLine::ARGUMENTS_ONLY);
495 BrowserInit::LaunchWithProfile launch(std::wstring(), dummy);
496 launch.profile_ = browser()->profile();
497 launch.OpenStartupURLs(std::vector<GURL>());
498
499 // The launch should have created a new browser.
500 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile()));
501
502 // Find the new browser.
503 Browser* new_browser = NULL;
504 for (BrowserList::const_iterator i = BrowserList::begin();
505 i != BrowserList::end() && !new_browser; ++i) {
506 if (*i != browser())
507 new_browser = *i;
508 }
509 ASSERT_TRUE(new_browser);
510 ASSERT_TRUE(new_browser != browser());
511
512 // We should get back an additional tab for the app.
513 ASSERT_EQ(2, new_browser->tab_count());
514
515 // Make sure the state matches.
516 TabStripModel* new_model = new_browser->tabstrip_model();
517 EXPECT_TRUE(new_model->IsAppTab(0));
518 EXPECT_FALSE(new_model->IsAppTab(1));
519
520 EXPECT_TRUE(new_model->IsTabPinned(0));
521 EXPECT_TRUE(new_model->IsTabPinned(1));
522
523 EXPECT_TRUE(new_model->GetTabContentsAt(0)->app_extension() ==
524 app_extension);
525 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698