#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
+#include "brightray/browser/net/devtools_network_conditions.h"
+#include "brightray/browser/net/devtools_network_controller.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
prefs::kDownloadDefaultDirectory, path);
}
+void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
+ scoped_ptr<brightray::DevToolsNetworkConditions> conditions;
+ bool offline = false;
+ double latency, download_throughput, upload_throughput;
+ if (options.Get("offline", &offline) && offline) {
+ conditions.reset(new brightray::DevToolsNetworkConditions(offline));
+ } else {
+ options.Get("latency", &latency);
+ options.Get("downloadThroughput", &download_throughput);
+ options.Get("uploadThroughput", &upload_throughput);
+ conditions.reset(
+ new brightray::DevToolsNetworkConditions(false,
+ latency,
+ download_throughput,
+ upload_throughput));
+ }
+ auto controller = browser_context_->GetDevToolsNetworkController();
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&brightray::DevToolsNetworkController::SetNetworkState,
+ base::Unretained(controller),
+ std::string(),
+ base::Passed(&conditions)));
+}
+
+void Session::DisableNetworkEmulation() {
+ scoped_ptr<brightray::DevToolsNetworkConditions> conditions(
+ new brightray::DevToolsNetworkConditions(false));
+ auto controller = browser_context_->GetDevToolsNetworkController();
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&brightray::DevToolsNetworkController::SetNetworkState,
+ base::Unretained(controller),
+ std::string(),
+ base::Passed(&conditions)));
+}
+
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
if (cookies_.IsEmpty()) {
auto handle = atom::api::Cookies::Create(isolate, browser_context());
.SetMethod("clearStorageData", &Session::ClearStorageData)
.SetMethod("setProxy", &Session::SetProxy)
.SetMethod("setDownloadPath", &Session::SetDownloadPath)
+ .SetMethod("enableNetworkEmulation", &Session::EnableNetworkEmulation)
+ .SetMethod("disableNetworkEmulation", &Session::DisableNetworkEmulation)
.SetProperty("cookies", &Session::Cookies);
}
Sets download saving directory. By default, the download directory will be the
`Downloads` under the respective app folder.
+
+### `session.enableNetworkEmulation(options)`
+
+* `options` Object
+ * `offline` Boolean - Whether to emulate network outage.
+ * `latency` Double - RTT in ms
+ * `downloadThroughput` Double - Download rate in Bps
+ * `uploadThroughput` Double - Upload rate in Bps
+
+Emulates network with the given configuration for the `session`.
+
+### `session.disableNetworkEmulation`
+
+Disables any network emulation already active for the `session`. Resets to
+the original network configuration.