| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 TabStripModel* model = browser()->tab_strip_model(); | 793 TabStripModel* model = browser()->tab_strip_model(); |
| 794 | 794 |
| 795 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 795 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); |
| 796 | 796 |
| 797 const Extension* extension_app = GetExtension(); | 797 const Extension* extension_app = GetExtension(); |
| 798 | 798 |
| 799 ui_test_utils::NavigateToURL(browser(), url); | 799 ui_test_utils::NavigateToURL(browser(), url); |
| 800 | 800 |
| 801 TabContents* app_contents = chrome::TabContentsFactory( | 801 TabContents* app_contents = chrome::TabContentsFactory( |
| 802 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL); | 802 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL); |
| 803 app_contents->extension_tab_helper()->SetExtensionApp(extension_app); | 803 extensions::TabHelper* extensions_tab_helper = |
| 804 extensions::TabHelper::FromWebContents(app_contents->web_contents()); |
| 805 extensions_tab_helper->SetExtensionApp(extension_app); |
| 804 | 806 |
| 805 model->AddTabContents(app_contents, 0, content::PageTransitionFromInt(0), | 807 model->AddTabContents(app_contents, 0, content::PageTransitionFromInt(0), |
| 806 TabStripModel::ADD_NONE); | 808 TabStripModel::ADD_NONE); |
| 807 model->SetTabPinned(0, true); | 809 model->SetTabPinned(0, true); |
| 808 ui_test_utils::NavigateToURL(browser(), url); | 810 ui_test_utils::NavigateToURL(browser(), url); |
| 809 | 811 |
| 810 MockTabStripModelObserver observer; | 812 MockTabStripModelObserver observer; |
| 811 model->AddObserver(&observer); | 813 model->AddObserver(&observer); |
| 812 | 814 |
| 813 // Uninstall the extension and make sure TabClosing is sent. | 815 // Uninstall the extension and make sure TabClosing is sent. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 914 |
| 913 // Add an pinned app tab. | 915 // Add an pinned app tab. |
| 914 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 916 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 915 GURL url(test_server()->GetURL("empty.html")); | 917 GURL url(test_server()->GetURL("empty.html")); |
| 916 TabStripModel* model = browser()->tab_strip_model(); | 918 TabStripModel* model = browser()->tab_strip_model(); |
| 917 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 919 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); |
| 918 const Extension* extension_app = GetExtension(); | 920 const Extension* extension_app = GetExtension(); |
| 919 ui_test_utils::NavigateToURL(browser(), url); | 921 ui_test_utils::NavigateToURL(browser(), url); |
| 920 TabContents* app_contents = chrome::TabContentsFactory( | 922 TabContents* app_contents = chrome::TabContentsFactory( |
| 921 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL); | 923 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL); |
| 922 app_contents->extension_tab_helper()->SetExtensionApp(extension_app); | 924 extensions::TabHelper* extensions_tab_helper = |
| 925 extensions::TabHelper::FromWebContents(app_contents->web_contents()); |
| 926 extensions_tab_helper->SetExtensionApp(extension_app); |
| 923 model->AddTabContents(app_contents, 0, content::PageTransitionFromInt(0), | 927 model->AddTabContents(app_contents, 0, content::PageTransitionFromInt(0), |
| 924 TabStripModel::ADD_NONE); | 928 TabStripModel::ADD_NONE); |
| 925 model->SetTabPinned(0, true); | 929 model->SetTabPinned(0, true); |
| 926 ui_test_utils::NavigateToURL(browser(), url); | 930 ui_test_utils::NavigateToURL(browser(), url); |
| 927 | 931 |
| 928 // Add a non pinned tab. | 932 // Add a non pinned tab. |
| 929 chrome::NewTab(browser()); | 933 chrome::NewTab(browser()); |
| 930 | 934 |
| 931 // Add a pinned non-app tab. | 935 // Add a pinned non-app tab. |
| 932 chrome::NewTab(browser()); | 936 chrome::NewTab(browser()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 EXPECT_FALSE(new_model->IsAppTab(2)); | 972 EXPECT_FALSE(new_model->IsAppTab(2)); |
| 969 | 973 |
| 970 EXPECT_TRUE(new_model->IsTabPinned(0)); | 974 EXPECT_TRUE(new_model->IsTabPinned(0)); |
| 971 EXPECT_TRUE(new_model->IsTabPinned(1)); | 975 EXPECT_TRUE(new_model->IsTabPinned(1)); |
| 972 EXPECT_FALSE(new_model->IsTabPinned(2)); | 976 EXPECT_FALSE(new_model->IsTabPinned(2)); |
| 973 | 977 |
| 974 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 978 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 975 new_model->GetTabContentsAt(2)->web_contents()->GetURL()); | 979 new_model->GetTabContentsAt(2)->web_contents()->GetURL()); |
| 976 | 980 |
| 977 EXPECT_TRUE( | 981 EXPECT_TRUE( |
| 978 new_model->GetTabContentsAt(0)->extension_tab_helper()->extension_app() == | 982 extensions::TabHelper::FromWebContents( |
| 979 extension_app); | 983 new_model->GetTabContentsAt(0)->web_contents())-> |
| 984 extension_app() == extension_app); |
| 980 } | 985 } |
| 981 #endif // !defined(OS_CHROMEOS) | 986 #endif // !defined(OS_CHROMEOS) |
| 982 | 987 |
| 983 // This test verifies we don't crash when closing the last window and the app | 988 // This test verifies we don't crash when closing the last window and the app |
| 984 // menu is showing. | 989 // menu is showing. |
| 985 IN_PROC_BROWSER_TEST_F(BrowserTest, CloseWithAppMenuOpen) { | 990 IN_PROC_BROWSER_TEST_F(BrowserTest, CloseWithAppMenuOpen) { |
| 986 if (browser_defaults::kBrowserAliveWithNoWindows) | 991 if (browser_defaults::kBrowserAliveWithNoWindows) |
| 987 return; | 992 return; |
| 988 | 993 |
| 989 // We need a message loop running for menus on windows. | 994 // We need a message loop running for menus on windows. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1000 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 1005 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); |
| 1001 const Extension* extension_app = GetExtension(); | 1006 const Extension* extension_app = GetExtension(); |
| 1002 | 1007 |
| 1003 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | 1008 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. |
| 1004 WebContents* app_window = application_launch::OpenApplication( | 1009 WebContents* app_window = application_launch::OpenApplication( |
| 1005 application_launch::LaunchParams(browser()->profile(), extension_app, | 1010 application_launch::LaunchParams(browser()->profile(), extension_app, |
| 1006 extension_misc::LAUNCH_WINDOW, | 1011 extension_misc::LAUNCH_WINDOW, |
| 1007 NEW_WINDOW)); | 1012 NEW_WINDOW)); |
| 1008 ASSERT_TRUE(app_window); | 1013 ASSERT_TRUE(app_window); |
| 1009 | 1014 |
| 1010 // Apps launched in a window from the NTP do not have extension_app set in | 1015 // Apps launched in a window from the NTP have an extensions tab helper but |
| 1011 // tab contents. | 1016 // do not have extension_app set in it. |
| 1012 TabContents* tab_contents = TabContents::FromWebContents(app_window); | 1017 ASSERT_TRUE(extensions::TabHelper::FromWebContents(app_window)); |
| 1013 EXPECT_FALSE(tab_contents->extension_tab_helper()->extension_app()); | 1018 EXPECT_FALSE( |
| 1019 extensions::TabHelper::FromWebContents(app_window)->extension_app()); |
| 1014 EXPECT_EQ(extension_app->GetFullLaunchURL(), app_window->GetURL()); | 1020 EXPECT_EQ(extension_app->GetFullLaunchURL(), app_window->GetURL()); |
| 1015 | 1021 |
| 1016 // The launch should have created a new browser. | 1022 // The launch should have created a new browser. |
| 1017 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); | 1023 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
| 1018 | 1024 |
| 1019 // Find the new browser. | 1025 // Find the new browser. |
| 1020 Browser* new_browser = NULL; | 1026 Browser* new_browser = NULL; |
| 1021 for (BrowserList::const_iterator i = BrowserList::begin(); | 1027 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 1022 i != BrowserList::end() && !new_browser; ++i) { | 1028 i != BrowserList::end() && !new_browser; ++i) { |
| 1023 if (*i != browser()) | 1029 if (*i != browser()) |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, | 1618 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, |
| 1613 NULL, NULL), | 1619 NULL, NULL), |
| 1614 0); | 1620 0); |
| 1615 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, | 1621 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, |
| 1616 NULL, NULL), | 1622 NULL, NULL), |
| 1617 0); | 1623 0); |
| 1618 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, | 1624 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, |
| 1619 true, NULL, NULL), | 1625 true, NULL, NULL), |
| 1620 0); | 1626 0); |
| 1621 } | 1627 } |
| OLD | NEW |