Chromium Code Reviews| 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 "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/ui/browser_command_controller.h" | 9 #include "chrome/browser/ui/browser_command_controller.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 12 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "components/zoom/zoom_controller.h" | 13 #include "components/zoom/zoom_controller.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | |
| 14 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/web_contents_tester.h" | 17 #include "content/public/test/web_contents_tester.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | |
| 17 | 19 |
| 18 using content::SiteInstance; | 20 using content::SiteInstance; |
| 19 using content::WebContents; | 21 using content::WebContents; |
| 20 using content::WebContentsTester; | 22 using content::WebContentsTester; |
| 21 | 23 |
| 22 class BrowserUnitTest : public BrowserWithTestWindowTest { | 24 class BrowserUnitTest : public BrowserWithTestWindowTest { |
| 23 public: | 25 public: |
| 24 BrowserUnitTest() {} | 26 BrowserUnitTest() {} |
| 25 ~BrowserUnitTest() override {} | 27 ~BrowserUnitTest() override {} |
| 26 | 28 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 contents2->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); | 61 contents2->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 60 EXPECT_TRUE(contents2->IsCrashed()); | 62 EXPECT_TRUE(contents2->IsCrashed()); |
| 61 | 63 |
| 62 // Selecting the second tab does not cause a load or clear the crash. | 64 // Selecting the second tab does not cause a load or clear the crash. |
| 63 tab_strip_model->ActivateTabAt(1, true); | 65 tab_strip_model->ActivateTabAt(1, true); |
| 64 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); | 66 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
| 65 EXPECT_FALSE(contents2->IsLoading()); | 67 EXPECT_FALSE(contents2->IsLoading()); |
| 66 EXPECT_TRUE(contents2->IsCrashed()); | 68 EXPECT_TRUE(contents2->IsCrashed()); |
| 67 } | 69 } |
| 68 | 70 |
| 71 TEST_F(BrowserUnitTest, SetBackgroundColorForNewTab) { | |
| 72 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 73 | |
| 74 WebContents* contents1 = CreateTestWebContents(); | |
| 75 tab_strip_model->AppendWebContents(contents1, true); | |
| 76 WebContentsTester::For(contents1)->NavigateAndCommit(GURL("about:blank")); | |
| 77 WebContentsTester::For(contents1)->TestSetIsLoading(false); | |
| 78 | |
| 79 contents1->GetMainFrame()->GetView()->SetBackgroundColor(SK_ColorRED); | |
| 80 | |
| 81 // Add a second tab in the background. | |
| 82 WebContents* contents2 = CreateTestWebContents(); | |
| 83 tab_strip_model->AppendWebContents(contents2, false); | |
| 84 WebContentsTester::For(contents2)->NavigateAndCommit(GURL("about:blank")); | |
| 85 WebContentsTester::For(contents2)->TestSetIsLoading(false); | |
| 86 | |
| 87 // Color is only set once the tab is activated. | |
|
Peter Kasting
2017/03/07 00:28:36
Why is it important to test this? It doesn't seem
chrishtr
2017/03/07 00:36:48
Fair point. Deleted this part.
| |
| 88 EXPECT_FALSE(SK_ColorRED == | |
| 89 contents2->GetMainFrame()->GetView()->background_color()); | |
| 90 | |
| 91 tab_strip_model->ActivateTabAt(1, true); | |
| 92 EXPECT_EQ(SK_ColorRED, | |
| 93 contents2->GetMainFrame()->GetView()->background_color()); | |
| 94 } | |
| 95 | |
| 69 // Ensure the print command gets disabled when a tab crashes. | 96 // Ensure the print command gets disabled when a tab crashes. |
| 70 TEST_F(BrowserUnitTest, DisablePrintOnCrashedTab) { | 97 TEST_F(BrowserUnitTest, DisablePrintOnCrashedTab) { |
| 71 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 98 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 72 | 99 |
| 73 WebContents* contents = CreateTestWebContents(); | 100 WebContents* contents = CreateTestWebContents(); |
| 74 tab_strip_model->AppendWebContents(contents, true); | 101 tab_strip_model->AppendWebContents(contents, true); |
| 75 WebContentsTester::For(contents)->NavigateAndCommit(GURL("about:blank")); | 102 WebContentsTester::For(contents)->NavigateAndCommit(GURL("about:blank")); |
| 76 | 103 |
| 77 CommandUpdater* command_updater = | 104 CommandUpdater* command_updater = |
| 78 browser()->command_controller()->command_updater(); | 105 browser()->command_controller()->command_updater(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // Activate the 1st tab which is NTP. | 245 // Activate the 1st tab which is NTP. |
| 219 browser()->tab_strip_model()->ActivateTabAt(0, true); | 246 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 220 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 247 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
| 221 EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state()); | 248 EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state()); |
| 222 | 249 |
| 223 // Activate the 2nd tab which is non-NTP. | 250 // Activate the 2nd tab which is non-NTP. |
| 224 browser()->tab_strip_model()->ActivateTabAt(1, true); | 251 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 225 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 252 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
| 226 EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state()); | 253 EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state()); |
| 227 } | 254 } |
| OLD | NEW |