summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/browser_proxy.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/automation/browser_proxy.cc')
-rw-r--r--chrome/test/automation/browser_proxy.cc64
1 files changed, 63 insertions, 1 deletions
diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc
index 1b275d8..5b5efca 100644
--- a/chrome/test/automation/browser_proxy.cc
+++ b/chrome/test/automation/browser_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,8 @@
#include <vector>
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/platform_thread.h"
#include "base/time.h"
@@ -594,3 +596,63 @@ bool BrowserProxy::SendJSONRequest(const std::string& request,
&result));
return result;
}
+
+bool BrowserProxy::GetInitialLoadTimes(float* min_start_time,
+ float* max_stop_time,
+ std::vector<float>* stop_times) {
+ std::string json_response;
+ const char* kJSONCommand = "{\"command\": \"GetInitialLoadTimes\"}";
+
+ *max_stop_time = 0;
+ *min_start_time = -1;
+ if (!SendJSONRequest(kJSONCommand, &json_response)) {
+ // Older browser versions do not support GetInitialLoadTimes.
+ // Fail gracefully and do not record them in this case.
+ return false;
+ }
+ std::string error;
+ base::JSONReader reader;
+ scoped_ptr<Value> values(reader.ReadAndReturnError(json_response, true,
+ NULL, &error));
+ if (!error.empty() || values->GetType() != Value::TYPE_DICTIONARY)
+ return false;
+
+ DictionaryValue* values_dict = static_cast<DictionaryValue*>(values.get());
+
+ Value* tabs_value;
+ if (!values_dict->Get(L"tabs", &tabs_value) ||
+ tabs_value->GetType() != Value::TYPE_LIST)
+ return false;
+
+ ListValue* tabs_list = static_cast<ListValue*>(tabs_value);
+
+ for (size_t i = 0; i < tabs_list->GetSize(); i++) {
+ float stop_ms = 0;
+ float start_ms = 0;
+ Value* tab_value;
+ DictionaryValue* tab_dict;
+
+ if (!tabs_list->Get(i, &tab_value) ||
+ tab_value->GetType() != Value::TYPE_DICTIONARY)
+ return false;
+ tab_dict = static_cast<DictionaryValue*>(tab_value);
+
+ double temp;
+ if (!tab_dict->GetReal(L"load_start_ms", &temp))
+ return false;
+ start_ms = static_cast<float>(temp);
+ // load_stop_ms can only be null if WaitForInitialLoads did not run.
+ if (!tab_dict->GetReal(L"load_stop_ms", &temp))
+ return false;
+ stop_ms = static_cast<float>(temp);
+
+ if (i == 0)
+ *min_start_time = start_ms;
+
+ *min_start_time = std::min(start_ms, *min_start_time);
+ *max_stop_time = std::max(stop_ms, *max_stop_time);
+ stop_times->push_back(stop_ms);
+ }
+ std::sort(stop_times->begin(), stop_times->end());
+ return true;
+}