• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/test/in_process_browser_test.h"
6 #include "chrome/test/ui_test_utils.h"
7 #include "chrome/common/url_constants.h"
8 #include "content/browser/tab_contents/navigation_controller.h"
9 #include "content/common/notification_registrar.h"
10 #include "content/common/notification_service.h"
11 #include "content/common/notification_source.h"
12 
13 namespace {
14 
15 class NavigationNotificationObserver : public NotificationObserver {
16  public:
NavigationNotificationObserver()17   NavigationNotificationObserver()
18       : got_navigation_(false),
19         http_status_code_(0) {
20     registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
21                    NotificationService::AllSources());
22   }
23 
Observe(NotificationType type,const NotificationSource & source,const NotificationDetails & details)24   virtual void Observe(NotificationType type,
25                        const NotificationSource& source,
26                        const NotificationDetails& details) OVERRIDE {
27     DCHECK_EQ(NotificationType::NAV_ENTRY_COMMITTED, type.value);
28     got_navigation_ = true;
29     http_status_code_ =
30         Details<NavigationController::LoadCommittedDetails>(details)->
31         http_status_code;
32   }
33 
http_status_code() const34   int http_status_code() const { return http_status_code_; }
got_navigation() const35   bool got_navigation() const { return got_navigation_; }
36 
37   private:
38   NotificationRegistrar registrar_;
39   int got_navigation_;
40   int http_status_code_;
41 
42   DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
43 };
44 
45 }  // namespace
46 
47 typedef InProcessBrowserTest ChromeURLDataManagerTest;
48 
49 // Makes sure navigating to the new tab page results in a http status code
50 // of 200.
51 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, 200) {
52   NavigationNotificationObserver observer;
53   ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
54   EXPECT_TRUE(observer.got_navigation());
55   EXPECT_EQ(200, observer.http_status_code());
56 }
57