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

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

Issue 1037003002: Only use web app frame for bookmark apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/ui/browser.cc ('k') | chrome/browser/ui/extensions/bookmark_app_browsertest.cc » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/ui/browser_tabstrip.h" 42 #include "chrome/browser/ui/browser_tabstrip.h"
43 #include "chrome/browser/ui/browser_ui_prefs.h" 43 #include "chrome/browser/ui/browser_ui_prefs.h"
44 #include "chrome/browser/ui/browser_window.h" 44 #include "chrome/browser/ui/browser_window.h"
45 #include "chrome/browser/ui/extensions/app_launch_params.h" 45 #include "chrome/browser/ui/extensions/app_launch_params.h"
46 #include "chrome/browser/ui/extensions/application_launch.h" 46 #include "chrome/browser/ui/extensions/application_launch.h"
47 #include "chrome/browser/ui/host_desktop.h" 47 #include "chrome/browser/ui/host_desktop.h"
48 #include "chrome/browser/ui/startup/startup_browser_creator.h" 48 #include "chrome/browser/ui/startup/startup_browser_creator.h"
49 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 49 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
50 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 50 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
51 #include "chrome/browser/ui/tabs/tab_strip_model.h" 51 #include "chrome/browser/ui/tabs/tab_strip_model.h"
52 #include "chrome/browser/web_applications/web_app.h"
53 #include "chrome/common/chrome_switches.h" 52 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 53 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
55 #include "chrome/common/pref_names.h" 54 #include "chrome/common/pref_names.h"
56 #include "chrome/common/url_constants.h" 55 #include "chrome/common/url_constants.h"
57 #include "chrome/grit/chromium_strings.h" 56 #include "chrome/grit/chromium_strings.h"
58 #include "chrome/grit/generated_resources.h" 57 #include "chrome/grit/generated_resources.h"
59 #include "chrome/test/base/in_process_browser_test.h" 58 #include "chrome/test/base/in_process_browser_test.h"
60 #include "chrome/test/base/test_switches.h" 59 #include "chrome/test/base/test_switches.h"
61 #include "chrome/test/base/ui_test_utils.h" 60 #include "chrome/test/base/ui_test_utils.h"
62 #include "components/app_modal/app_modal_dialog.h" 61 #include "components/app_modal/app_modal_dialog.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 202
204 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app 203 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app
205 // menu. 204 // menu.
206 void RunCloseWithAppMenuCallback(Browser* browser) { 205 void RunCloseWithAppMenuCallback(Browser* browser) {
207 // ShowAppMenu is modal under views. Schedule a task that closes the window. 206 // ShowAppMenu is modal under views. Schedule a task that closes the window.
208 base::MessageLoop::current()->PostTask( 207 base::MessageLoop::current()->PostTask(
209 FROM_HERE, base::Bind(&CloseWindowCallback, browser)); 208 FROM_HERE, base::Bind(&CloseWindowCallback, browser));
210 chrome::ShowAppMenu(browser); 209 chrome::ShowAppMenu(browser);
211 } 210 }
212 211
213 #if !defined(OS_MACOSX)
214 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that
215 // the location bar visibility is as expcted.
216 void NavigateAndCheckForLocationBar(Browser* browser,
217 const std::string& url_string,
218 bool expected_visibility) {
219 GURL url(url_string);
220 ui_test_utils::NavigateToURL(browser, url);
221 EXPECT_EQ(expected_visibility,
222 browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
223 }
224 #endif // !defined(OS_MACOSX)
225
226 // Displays "INTERSTITIAL" while the interstitial is attached. 212 // Displays "INTERSTITIAL" while the interstitial is attached.
227 // (InterstitialPage can be used in a test directly, but there would be no way 213 // (InterstitialPage can be used in a test directly, but there would be no way
228 // to visually tell if it is showing or not.) 214 // to visually tell if it is showing or not.)
229 class TestInterstitialPage : public content::InterstitialPageDelegate { 215 class TestInterstitialPage : public content::InterstitialPageDelegate {
230 public: 216 public:
231 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { 217 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) {
232 interstitial_page_ = InterstitialPage::Create( 218 interstitial_page_ = InterstitialPage::Create(
233 tab, new_navigation, url , this); 219 tab, new_navigation, url , this);
234 interstitial_page_->Show(); 220 interstitial_page_->Show();
235 } 221 }
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 ASSERT_TRUE(app_browser); 1379 ASSERT_TRUE(app_browser);
1394 ASSERT_TRUE(app_browser != browser()); 1380 ASSERT_TRUE(app_browser != browser());
1395 1381
1396 EXPECT_FALSE( 1382 EXPECT_FALSE(
1397 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); 1383 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
1398 EXPECT_FALSE( 1384 EXPECT_FALSE(
1399 app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); 1385 app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
1400 1386
1401 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); 1387 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
1402 } 1388 }
1403
1404 // Check that the location bar is shown correctly for HTTP bookmark apps.
1405 IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldShowLocationBarForHTTPBookmarkApp) {
1406 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1407 switches::kEnableNewBookmarkApps);
1408 ASSERT_TRUE(test_server()->Start());
1409
1410 // Load a http bookmark app.
1411 const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags(
1412 test_data_dir_.AppendASCII("app/"),
1413 1,
1414 extensions::Manifest::INTERNAL,
1415 extensions::Extension::FROM_BOOKMARK);
1416 ASSERT_TRUE(http_bookmark_app);
1417
1418 // Launch it in a window.
1419 WebContents* app_window = OpenApplication(AppLaunchParams(
1420 browser()->profile(), http_bookmark_app,
1421 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
1422 extensions::SOURCE_TEST));
1423 ASSERT_TRUE(app_window);
1424
1425 // Find the new browser.
1426 Browser* http_app_browser = NULL;
1427 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1428 std::string app_id =
1429 web_app::GetExtensionIdFromApplicationName((*it)->app_name());
1430 if (*it == browser()) {
1431 continue;
1432 } else if (app_id == http_bookmark_app->id()) {
1433 http_app_browser = *it;
1434 }
1435 }
1436 ASSERT_TRUE(http_app_browser);
1437 ASSERT_TRUE(http_app_browser != browser());
1438
1439 // Navigate to the app's launch page; the location bar should be hidden.
1440 NavigateAndCheckForLocationBar(
1441 http_app_browser, "http://www.example.com/empty.html", false);
1442
1443 // Navigate to another page on the same origin; the location bar should still
1444 // hidden.
1445 NavigateAndCheckForLocationBar(
1446 http_app_browser, "http://www.example.com/blah", false);
1447
1448 // Navigate to the https version of the site; the location bar should
1449 // be hidden for both browsers.
1450 NavigateAndCheckForLocationBar(
1451 http_app_browser, "https://www.example.com/blah", false);
1452
1453 // Navigate to different origin; the location bar should now be visible.
1454 NavigateAndCheckForLocationBar(
1455 http_app_browser, "http://www.foo.com/blah", true);
1456
1457 // Navigate back to the app's origin; the location bar should now be hidden.
1458 NavigateAndCheckForLocationBar(
1459 http_app_browser, "http://www.example.com/blah", false);
1460 }
1461
1462 // Check that the location bar is shown correctly for HTTPS bookmark apps.
1463 IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldShowLocationBarForHTTPSBookmarkApp) {
1464 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1465 switches::kEnableNewBookmarkApps);
1466 ASSERT_TRUE(test_server()->Start());
1467
1468 // Load a https bookmark app.
1469 const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags(
1470 test_data_dir_.AppendASCII("https_app/"),
1471 1,
1472 extensions::Manifest::INTERNAL,
1473 extensions::Extension::FROM_BOOKMARK);
1474 ASSERT_TRUE(https_bookmark_app);
1475
1476 // Launch it in a window.
1477 WebContents* app_window = OpenApplication(AppLaunchParams(
1478 browser()->profile(), https_bookmark_app,
1479 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
1480 extensions::SOURCE_TEST));
1481 ASSERT_TRUE(app_window);
1482
1483 // Find the new browser.
1484 Browser* https_app_browser = NULL;
1485 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1486 std::string app_id =
1487 web_app::GetExtensionIdFromApplicationName((*it)->app_name());
1488 if (*it == browser()) {
1489 continue;
1490 } else if (app_id == https_bookmark_app->id()) {
1491 https_app_browser = *it;
1492 }
1493 }
1494 ASSERT_TRUE(https_app_browser);
1495 ASSERT_TRUE(https_app_browser != browser());
1496
1497 // Navigate to the app's launch page; the location bar should be hidden.
1498 NavigateAndCheckForLocationBar(
1499 https_app_browser, "https://www.example.com/empty.html", false);
1500
1501 // Navigate to another page on the same origin; the location bar should still
1502 // hidden.
1503 NavigateAndCheckForLocationBar(
1504 https_app_browser, "https://www.example.com/blah", false);
1505
1506 // Navigate to the http version of the site; the location bar should
1507 // be visible for the https version as it is now on a less secure version
1508 // of its host.
1509 NavigateAndCheckForLocationBar(
1510 https_app_browser, "http://www.example.com/blah", true);
1511
1512 // Navigate to different origin; the location bar should now be visible.
1513 NavigateAndCheckForLocationBar(
1514 https_app_browser, "http://www.foo.com/blah", true);
1515
1516 // Navigate back to the app's origin; the location bar should now be hidden.
1517 NavigateAndCheckForLocationBar(
1518 https_app_browser, "https://www.example.com/blah", false);
1519 }
1520 #endif // !defined(OS_MACOSX) 1389 #endif // !defined(OS_MACOSX)
1521 1390
1522 // Open a normal browser window, a hosted app window, a legacy packaged app
1523 // window and a dev tools window, and check that the web app frame feature is
1524 // supported correctly.
1525 IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldUseWebAppFrame) {
1526 ASSERT_TRUE(test_server()->Start());
1527 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1528 switches::kEnableWebAppFrame);
1529
1530 // Load a hosted app.
1531 host_resolver()->AddRule("www.example.com", "127.0.0.1");
1532 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/")));
1533 const Extension* hosted_app = GetExtension();
1534
1535 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would.
1536 WebContents* hosted_app_window = OpenApplication(AppLaunchParams(
1537 browser()->profile(), hosted_app, extensions::LAUNCH_CONTAINER_WINDOW,
1538 NEW_WINDOW, extensions::SOURCE_UNTRACKED));
1539 ASSERT_TRUE(hosted_app_window);
1540
1541 // Load a packaged app.
1542 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app/")));
1543 const Extension* packaged_app = nullptr;
1544 extensions::ExtensionRegistry* registry =
1545 extensions::ExtensionRegistry::Get(browser()->profile());
1546 for (const scoped_refptr<const extensions::Extension>& extension :
1547 registry->enabled_extensions()) {
1548 if (extension->name() == "Packaged App Test")
1549 packaged_app = extension.get();
1550 }
1551 ASSERT_TRUE(packaged_app);
1552
1553 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would.
1554 WebContents* packaged_app_window = OpenApplication(AppLaunchParams(
1555 browser()->profile(), packaged_app, extensions::LAUNCH_CONTAINER_WINDOW,
1556 NEW_WINDOW, extensions::SOURCE_UNTRACKED));
1557 ASSERT_TRUE(packaged_app_window);
1558
1559 DevToolsWindow* devtools_window =
1560 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
1561
1562 // The launch should have created a new app browser and a dev tools browser.
1563 ASSERT_EQ(4u, chrome::GetBrowserCount(browser()->profile(),
1564 browser()->host_desktop_type()));
1565
1566 // Find the new browsers.
1567 Browser* hosted_app_browser = NULL;
1568 Browser* packaged_app_browser = NULL;
1569 Browser* dev_tools_browser = NULL;
1570 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1571 if (*it == browser()) {
1572 continue;
1573 } else if ((*it)->app_name() == DevToolsWindow::kDevToolsApp) {
1574 dev_tools_browser = *it;
1575 } else if ((*it)->tab_strip_model()->GetActiveWebContents() ==
1576 hosted_app_window) {
1577 hosted_app_browser = *it;
1578 } else {
1579 packaged_app_browser = *it;
1580 }
1581 }
1582 ASSERT_TRUE(dev_tools_browser);
1583 ASSERT_TRUE(hosted_app_browser);
1584 ASSERT_TRUE(hosted_app_browser != browser());
1585 ASSERT_TRUE(packaged_app_browser);
1586 ASSERT_TRUE(packaged_app_browser != browser());
1587 ASSERT_TRUE(packaged_app_browser != hosted_app_browser);
1588
1589 EXPECT_FALSE(browser()->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME));
1590 EXPECT_FALSE(
1591 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME));
1592 EXPECT_EQ(
1593 browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH,
1594 hosted_app_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME));
1595 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature(
1596 Browser::FEATURE_WEBAPPFRAME));
1597
1598 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
1599 }
1600
1601 // Tests that the CLD (Compact Language Detection) works properly. 1391 // Tests that the CLD (Compact Language Detection) works properly.
1602 IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { 1392 IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) {
1603 scoped_ptr<test::CldDataHarness> cld_data_harness = 1393 scoped_ptr<test::CldDataHarness> cld_data_harness =
1604 test::CldDataHarnessFactory::Get()->CreateCldDataHarness(); 1394 test::CldDataHarnessFactory::Get()->CreateCldDataHarness();
1605 ASSERT_NO_FATAL_FAILURE(cld_data_harness->Init()); 1395 ASSERT_NO_FATAL_FAILURE(cld_data_harness->Init());
1606 ASSERT_TRUE(test_server()->Start()); 1396 ASSERT_TRUE(test_server()->Start());
1607 1397
1608 translate::LanguageDetectionDetails details; 1398 translate::LanguageDetectionDetails details;
1609 1399
1610 // Open a new tab with a page in English. 1400 // Open a new tab with a page in English.
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 #endif 2699 #endif
2910 EXPECT_EQ(exp_commit_size, rwhv_commit_size2); 2700 EXPECT_EQ(exp_commit_size, rwhv_commit_size2);
2911 EXPECT_EQ(exp_commit_size, wcv_commit_size2); 2701 EXPECT_EQ(exp_commit_size, wcv_commit_size2);
2912 gfx::Size exp_final_size(initial_wcv_size); 2702 gfx::Size exp_final_size(initial_wcv_size);
2913 exp_final_size.Enlarge(wcv_resize_insets.width(), 2703 exp_final_size.Enlarge(wcv_resize_insets.width(),
2914 wcv_resize_insets.height() + height_inset); 2704 wcv_resize_insets.height() + height_inset);
2915 EXPECT_EQ(exp_final_size, 2705 EXPECT_EQ(exp_final_size,
2916 web_contents->GetRenderWidgetHostView()->GetViewBounds().size()); 2706 web_contents->GetRenderWidgetHostView()->GetViewBounds().size());
2917 EXPECT_EQ(exp_final_size, web_contents->GetContainerBounds().size()); 2707 EXPECT_EQ(exp_final_size, web_contents->GetContainerBounds().size());
2918 } 2708 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/extensions/bookmark_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698