| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/page_navigator.h" | 30 #include "content/public/browser/page_navigator.h" |
| 31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
| 34 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 35 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 37 | 37 |
| 38 // Class used to run a message loop waiting for the TabRestoreService to finish | 38 // Class used to run a message loop waiting for the TabRestoreService to finish |
| 39 // loading. Does nothing if the TabRestoreService was already loaded. | 39 // loading. Does nothing if the TabRestoreService was already loaded. |
| 40 class WaitForLoadObserver : public TabRestoreServiceObserver { | 40 class WaitForLoadObserver : public sessions::TabRestoreServiceObserver { |
| 41 public: | 41 public: |
| 42 explicit WaitForLoadObserver(Browser* browser) | 42 explicit WaitForLoadObserver(Browser* browser) |
| 43 : tab_restore_service_( | 43 : tab_restore_service_( |
| 44 TabRestoreServiceFactory::GetForProfile(browser->profile())), | 44 TabRestoreServiceFactory::GetForProfile(browser->profile())), |
| 45 do_wait_(!tab_restore_service_->IsLoaded()) { | 45 do_wait_(!tab_restore_service_->IsLoaded()) { |
| 46 if (do_wait_) | 46 if (do_wait_) |
| 47 tab_restore_service_->AddObserver(this); | 47 tab_restore_service_->AddObserver(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ~WaitForLoadObserver() override { | 50 ~WaitForLoadObserver() override { |
| 51 if (do_wait_) | 51 if (do_wait_) |
| 52 tab_restore_service_->RemoveObserver(this); | 52 tab_restore_service_->RemoveObserver(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Wait() { | 55 void Wait() { |
| 56 if (do_wait_) | 56 if (do_wait_) |
| 57 run_loop_.Run(); | 57 run_loop_.Run(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 // Overridden from TabRestoreServiceObserver: | 61 // Overridden from TabRestoreServiceObserver: |
| 62 void TabRestoreServiceChanged(TabRestoreService* service) override {} | 62 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override { |
| 63 void TabRestoreServiceDestroyed(TabRestoreService* service) override {} | 63 } |
| 64 void TabRestoreServiceLoaded(TabRestoreService* service) override { | 64 void TabRestoreServiceDestroyed( |
| 65 sessions::TabRestoreService* service) override {} |
| 66 void TabRestoreServiceLoaded(sessions::TabRestoreService* service) override { |
| 65 DCHECK(do_wait_); | 67 DCHECK(do_wait_); |
| 66 run_loop_.Quit(); | 68 run_loop_.Quit(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 TabRestoreService* tab_restore_service_; | 71 sessions::TabRestoreService* tab_restore_service_; |
| 70 const bool do_wait_; | 72 const bool do_wait_; |
| 71 base::RunLoop run_loop_; | 73 base::RunLoop run_loop_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(WaitForLoadObserver); | 75 DISALLOW_COPY_AND_ASSIGN(WaitForLoadObserver); |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 class TabRestoreTest : public InProcessBrowserTest { | 78 class TabRestoreTest : public InProcessBrowserTest { |
| 77 public: | 79 public: |
| 78 TabRestoreTest() : active_browser_list_(NULL) { | 80 TabRestoreTest() : active_browser_list_(NULL) { |
| 79 url1_ = ui_test_utils::GetTestUrl( | 81 url1_ = ui_test_utils::GetTestUrl( |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 while (browser()->tab_strip_model()->count()) | 627 while (browser()->tab_strip_model()->count()) |
| 626 CloseTab(0); | 628 CloseTab(0); |
| 627 } | 629 } |
| 628 | 630 |
| 629 // Verifies restoring a tab works on startup. | 631 // Verifies restoring a tab works on startup. |
| 630 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { | 632 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { |
| 631 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); | 633 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); |
| 632 EXPECT_EQ(url1_, | 634 EXPECT_EQ(url1_, |
| 633 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); | 635 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
| 634 } | 636 } |
| OLD | NEW |