OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_base.h" | 9 #include "base/metrics/histogram_base.h" |
10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 EXPECT_TRUE(ExecuteScript(stream.str())); | 1360 EXPECT_TRUE(ExecuteScript(stream.str())); |
1361 observer.Wait(); | 1361 observer.Wait(); |
1362 | 1362 |
1363 // Update Most Visited state. | 1363 // Update Most Visited state. |
1364 EXPECT_TRUE(UpdateSearchState(overlay)); | 1364 EXPECT_TRUE(UpdateSearchState(overlay)); |
1365 | 1365 |
1366 // Make sure we have the same number of items as before. | 1366 // Make sure we have the same number of items as before. |
1367 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); | 1367 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); |
1368 } | 1368 } |
1369 | 1369 |
1370 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { | |
1371 InstallThemeSource(); | |
1372 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); | |
1373 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
1374 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
1375 | 1370 |
1376 // The "Instant" New Tab should have access to chrome-search: scheme but not | |
1377 // chrome: scheme. | |
1378 ui_test_utils::NavigateToURLWithDisposition( | |
1379 browser(), | |
1380 GURL(chrome::kChromeUINewTabURL), | |
1381 NEW_FOREGROUND_TAB, | |
1382 ui_test_utils::BROWSER_TEST_NONE); | |
1383 | |
1384 content::RenderViewHost* rvh = | |
1385 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | |
1386 | |
1387 const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); | |
1388 const std::string search_url( | |
1389 "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); | |
1390 bool loaded = false; | |
1391 ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); | |
1392 EXPECT_FALSE(loaded) << chrome_url; | |
1393 ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); | |
1394 EXPECT_TRUE(loaded) << search_url; | |
1395 } | |
1396 | 1371 |
1397 // TODO(dhollowa): Fix flakes. http://crbug.com/179930. | 1372 // TODO(dhollowa): Fix flakes. http://crbug.com/179930. |
1398 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) { | 1373 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) { |
1399 // Create a favicon. | 1374 // Create a favicon. |
1400 history::TopSites* top_sites = browser()->profile()->GetTopSites(); | 1375 history::TopSites* top_sites = browser()->profile()->GetTopSites(); |
1401 GURL url("http://www.google.com/foo.html"); | 1376 GURL url("http://www.google.com/foo.html"); |
1402 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); | 1377 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); |
1403 ThumbnailScore high_score(0.0, true, true, base::Time::Now()); | 1378 ThumbnailScore high_score(0.0, true, true, base::Time::Now()); |
1404 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); | 1379 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); |
1405 | 1380 |
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2891 browser()->tab_strip_model()->ActivateTabAt(0, false); | 2866 browser()->tab_strip_model()->ActivateTabAt(0, false); |
2892 | 2867 |
2893 // Switch back to new tab. | 2868 // Switch back to new tab. |
2894 browser()->tab_strip_model()->ActivateTabAt(1, false); | 2869 browser()->tab_strip_model()->ActivateTabAt(1, false); |
2895 | 2870 |
2896 // Confirm that new tab got no onmostvisitedchanged event. | 2871 // Confirm that new tab got no onmostvisitedchanged event. |
2897 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2872 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2898 EXPECT_TRUE(UpdateSearchState(active_tab)); | 2873 EXPECT_TRUE(UpdateSearchState(active_tab)); |
2899 EXPECT_EQ(2, on_most_visited_change_calls_); | 2874 EXPECT_EQ(2, on_most_visited_change_calls_); |
2900 } | 2875 } |
| 2876 |
| 2877 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { |
| 2878 InstallThemeSource(); |
| 2879 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
| 2880 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2881 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2882 |
| 2883 // The "Instant" New Tab should have access to chrome-search: scheme but not |
| 2884 // chrome: scheme. |
| 2885 ui_test_utils::NavigateToURLWithDisposition( |
| 2886 browser(), |
| 2887 GURL(chrome::kChromeUINewTabURL), |
| 2888 NEW_FOREGROUND_TAB, |
| 2889 ui_test_utils::BROWSER_TEST_NONE); |
| 2890 |
| 2891 content::RenderViewHost* rvh = |
| 2892 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
| 2893 |
| 2894 const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); |
| 2895 const std::string search_url( |
| 2896 "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); |
| 2897 bool loaded = false; |
| 2898 ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); |
| 2899 EXPECT_FALSE(loaded) << chrome_url; |
| 2900 ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); |
| 2901 EXPECT_TRUE(loaded) << search_url; |
| 2902 } |
| 2903 |
| 2904 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, |
| 2905 NoThemeBackgroundChangeEventOnTabSwitch) { |
| 2906 InstallThemeSource(); |
| 2907 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2908 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2909 |
| 2910 // Install a theme. |
| 2911 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
| 2912 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2913 |
| 2914 // Open new tab. Preloaded NTP contents should have been used. |
| 2915 ui_test_utils::NavigateToURLWithDisposition( |
| 2916 browser(), |
| 2917 GURL(chrome::kChromeUINewTabURL), |
| 2918 NEW_FOREGROUND_TAB, |
| 2919 ui_test_utils::BROWSER_TEST_NONE); |
| 2920 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 2921 |
| 2922 content::WebContents* active_tab = |
| 2923 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2924 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 2925 int on_theme_changed_calls = 0; |
| 2926 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", |
| 2927 &on_theme_changed_calls)); |
| 2928 EXPECT_EQ(1, on_theme_changed_calls); |
| 2929 |
| 2930 // Activate the previous tab. |
| 2931 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 2932 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 2933 |
| 2934 // Switch back to new tab. |
| 2935 browser()->tab_strip_model()->ActivateTabAt(1, false); |
| 2936 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 2937 |
| 2938 // Confirm that new tab got no onthemechanged event while switching tabs. |
| 2939 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2940 on_theme_changed_calls = 0; |
| 2941 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", |
| 2942 &on_theme_changed_calls)); |
| 2943 EXPECT_EQ(1, on_theme_changed_calls); |
| 2944 } |
| 2945 |
| 2946 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, |
| 2947 SendThemeBackgroundChangedEvent) { |
| 2948 InstallThemeSource(); |
| 2949 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2950 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2951 |
| 2952 // Install a theme. |
| 2953 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
| 2954 |
| 2955 // Open new tab. Preloaded NTP contents should have been used. |
| 2956 ui_test_utils::NavigateToURLWithDisposition( |
| 2957 browser(), |
| 2958 GURL(chrome::kChromeUINewTabURL), |
| 2959 NEW_FOREGROUND_TAB, |
| 2960 ui_test_utils::BROWSER_TEST_NONE); |
| 2961 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 2962 |
| 2963 // Make sure new tab received an onthemechanged event. |
| 2964 content::WebContents* active_tab = |
| 2965 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2966 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 2967 int on_theme_changed_calls = 0; |
| 2968 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", |
| 2969 &on_theme_changed_calls)); |
| 2970 EXPECT_EQ(1, on_theme_changed_calls); |
| 2971 |
| 2972 // Install a new theme. |
| 2973 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme2", "snowflake theme")); |
| 2974 |
| 2975 // Confirm that new tab is notified about the theme changed event. |
| 2976 on_theme_changed_calls = 0; |
| 2977 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", |
| 2978 &on_theme_changed_calls)); |
| 2979 EXPECT_EQ(2, on_theme_changed_calls); |
| 2980 } |
OLD | NEW |