• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 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 #ifndef CHROME_TEST_CHROMEDRIVER_CHROME_NAVIGATION_TRACKER_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_NAVIGATION_TRACKER_H_
7 
8 #include <set>
9 #include <string>
10 
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
15 #include "chrome/test/chromedriver/chrome/status.h"
16 
17 namespace base {
18 class DictionaryValue;
19 }
20 
21 struct BrowserInfo;
22 class DevToolsClient;
23 class Status;
24 
25 // Tracks the navigation state of the page.
26 class NavigationTracker : public DevToolsEventListener {
27  public:
28   enum LoadingState {
29     kUnknown,
30     kLoading,
31     kNotLoading,
32   };
33 
34   NavigationTracker(DevToolsClient* client, const BrowserInfo* browser_info);
35 
36   NavigationTracker(DevToolsClient* client,
37                     LoadingState known_state,
38                     const BrowserInfo* browser_info);
39 
40   virtual ~NavigationTracker();
41 
42   // Gets whether a navigation is pending for the specified frame. |frame_id|
43   // may be empty to signify the main frame.
44   Status IsPendingNavigation(const std::string& frame_id, bool* is_pending);
45 
46   // Overridden from DevToolsEventListener:
47   virtual Status OnConnected(DevToolsClient* client) OVERRIDE;
48   virtual Status OnEvent(DevToolsClient* client,
49                          const std::string& method,
50                          const base::DictionaryValue& params) OVERRIDE;
51   virtual Status OnCommandSuccess(DevToolsClient* client,
52                                   const std::string& method) OVERRIDE;
53 
54  private:
55   DevToolsClient* client_;
56   LoadingState loading_state_;
57   const BrowserInfo* browser_info_;
58   int num_frames_pending_;
59   std::set<std::string> scheduled_frame_set_;
60 
61   void ResetLoadingState(LoadingState loading_state);
62 
63   DISALLOW_COPY_AND_ASSIGN(NavigationTracker);
64 };
65 
66 #endif  // CHROME_TEST_CHROMEDRIVER_CHROME_NAVIGATION_TRACKER_H_
67