Best JavaScript code snippet using wpt
controllers.js
Source:controllers.js
1'use strict';2/* Controllers */3var myAppCtrl = angular.module('myApp.controllers', []);4myAppCtrl.controller('MonitoringCtrl', 5 ['socket','$scope', '$http', 'Monitoring',6 function(socket, $scope, $http, Monitoring) {7 //Init general variables;8 $scope.serverMonitoring = "http://localhost:8000/";9 $scope.graphs = undefined;10 var initGraph = function (graphName){11 $scope.graphs[graphName] = {12 last: [],13 data: [],14 opts: { 15 title: 'CPU Temperature',16 labels: [ "Time", "°C"], 17 //ylabel: 'Temperature (°C)',18 width: 1024,19 height: 300,20 showRangeSelector: true,21 rollPeriod: 1,22 xRangePad:1,23 showRoller: true,24 legend: 'always'25 }26 };27 };28 socket.on('newValue', function(data){29 //console.log("New data from server");30 var timestamp = data.datetime - 600000; //10min31 var graphName = data.probe_history_table_uid;32 if(!$scope.graphs){33 $scope.graphs = {};34 }35 if(!$scope.graphs[graphName]){36 initGraph(graphName);37 }38 // $scope.graphs[graphName].opts.dateWindow = [new Date(timestamp), new Date(data.datetime)];39 var date=new Date(data.timestamp);40 $scope.graphs[graphName].data = $scope.graphs[graphName].data+""+ date+","+ data.value+"\n";41 $scope.graphs[graphName].last = [date, data.value];42 });43 $scope.updateCharts = function (){44 Monitoring.getProbesManagement()45 .then(function(data){46 var item = data[0];47 for (var i = 0, item; item = data[i]; i++) {48 var graphName = item.probe_history_table_uid;49 if(!$scope.graphs){50 $scope.graphs = {};51 }52 if(!$scope.graphs[graphName]){53 initGraph(graphName);54 }55 $scope.graphs[graphName].opts.title = "| "+item.probe_name+" | "+item.probe_type+"";56 $scope.graphs[graphName].opts.labels = [ "Time", item.unit];57 $http.get($scope.serverMonitoring+'monitoring.csv?callback=getProbeHistory&historyTable='+item.probe_history_table_uid)58 .success(function(data, status, headers, config){59 var graphName = config.url.replace(/.*historyTable=/, '');60 $scope.graphs[graphName].data = data;61 //Get last value62 var lines = data.trim().split('\n');63 var lastLine = lines.slice(-1)[0];64 var fields = lastLine.split(',');65 $scope.graphs[graphName].last = fields;66 });67 }68 });69 70 /* .error(function(err){71 console.error(err);72 });*/73 }74 $scope.updateCharts();75}]); 76myAppCtrl.controller('AdminProbesCtrl', 77 ['$scope', '$http', 'Monitoring', 78 function($scope, $http, Monitoring ) {79 //////////////////////////////////////////80 //Init general variables;81 //////////////////////////////////////////82 $scope.serverMonitoring = "http://localhost:8000/";83 $scope.newProbe={probe_uid: -1, probe_name: "Simulation probe", description:"This probe use a fack sensor to get random temperature data."};84 $scope.newProbeConfig={probe_config_uid: -1, probe_type: "Temperature", node_module:"fack-sensor", unit:"°C"};85 $scope.newProbeAcquMode={probe_acqu_mode_uid: -1, acquisition_mode_name: "Default mode", acquisition_mode:"ASAP"};86 $scope.selectAMode={probe_acqu_mode_uid: -2, acquisition_mode_name: "Please, select a mode!"};87 $scope.acquModeOptions=['ASAP', 'ONTIME'];88 //////////////////////////////////////////89 // Init methods90 //////////////////////////////////////////91 $scope.initProbesList = function(){92 $scope.probeSelected_uid = -1;93 $scope.probeSelected = undefined;94 $scope.probes = [];95 };96 $scope.initProbeConfigList = function(){97 $scope.probeAcquModeSelected_uid = -1;98 $scope.probeAcquModeSelected = undefined;99 $scope.probeConfig = [];100 };101 $scope.initProbeAcquModeList = function(){102 $scope.probeConfigSelected_uid = -1;103 $scope.probeConfigSelected = undefined;104 $scope.probeAcquMode = [];105 };106 //////////////////////////////////////////107 // Get data from DB108 //////////////////////////////////////////109 $scope.getProbeAcquMode = function (){110 Monitoring.getProbeAcquMode()111 .then(function(data){112 if(data.length !== 0){113 $scope.probeAcquMode = data;114 if($scope.probeConfigSelected != undefined &&115 $scope.probeConfigSelected.probe_acqu_mode_uid !=null ){116 var item = $scope.probeAcquMode[0];117 for (var i = 0, item; item = $scope.probeAcquMode[i]; i++) {118 if($scope.probeConfigSelected.probe_acqu_mode_uid === item.probe_acqu_mode_uid){119 $scope.probeAcquModeSelected = item;120 }121 }122 }123 else if($scope.probeAcquModeSelected === undefined ||124 $scope.probeAcquModeSelected_uid === -1){125 $scope.probeAcquModeSelected = $scope.probeAcquMode[$scope.probeAcquMode.length-1];126 }127 $scope.probeAcquModeSelected_uid = $scope.probeAcquModeSelected.probe_acqu_mode_uid;128 }129 else{130 $scope.initProbeAcquModeList();131 }132 });133 };134 $scope.getProbeConfig = function (probeUID){135 Monitoring.getProbeConfig(probeUID)136 .then(function(data){137 if(data.length !== 0){138 $scope.probeConfig = data;139 if($scope.probeConfigSelected === undefined ||140 $scope.probeConfigSelected_uid === -1){141 $scope.probeConfigSelected = $scope.probeConfig[$scope.probeConfig.length-1];142 }143 $scope.probeConfigSelected_uid = $scope.probeConfigSelected.probe_config_uid;144 $scope.getProbeAcquMode();145 }146 else{147 $scope.initProbeConfigList();148 }149 });150 };151 $scope.getProbes = function (){152 Monitoring.getProbes()153 .then(function(data){154 if(data.length !== 0){155 $scope.probes = data;156 if($scope.probeSelected === undefined ||157 $scope.probeSelected_uid === -1){158 $scope.probeSelected = $scope.probes[$scope.probes.length-1];159 }160 $scope.probeSelected_uid = $scope.probeSelected.probe_uid;161 $scope.getProbeConfig($scope.probeSelected_uid);162 }163 else{164 $scope.initProbesList();165 }166 });167 };168 //////////////////////////////////////////169 // Operation on database 170 //////////////////////////////////////////171 $scope.addProbe = function (){172 $scope.probes.concat($scope.newProbe);173 $scope.probeSelected = $scope.newProbe;174 $scope.probeConfigSelected = $scope.newProbeConfig;175 $scope.probeSelected_uid = $scope.probeSelected.probe_uid;176 $scope.probeConfigSelected_uid = $scope.probeConfigSelected.probe_config_uid;177 $http.post($scope.serverMonitoring+'monitoring.query?callback=addProbe', $scope.newProbe).then(178 function(response){179 $scope.refresh();180 });181 };182 $scope.updateProbe = function (){183 $http.post($scope.serverMonitoring+'monitoring.query?callback=updateProbe', $scope.probeSelected).then(184 function(response){185 $scope.refresh();186 });187 };188 $scope.rmProbe = function (){189 if($scope.probeSelected_uid){190 $http.get($scope.serverMonitoring+'monitoring.query?callback=rmProbe&probeUID='+$scope.probeSelected_uid).then(191 function(response){192 $scope.probeSelected_uid = -1;193 $scope.probeConfigSelected_uid = -1;194 $scope.refresh();195 });196 }197 };198 $scope.addProbeConfig = function (){199 $scope.probeConfig.concat($scope.newProbeConfig);200 $scope.probeConfigSelected = $scope.newProbeConfig;201 $scope.probeConfigSelected_uid = $scope.probeConfigSelected.probe_config_uid;202 $scope.probeAcquModeSelected = $scope.selectAMode;203 $scope.probeAcquModeSelected_uid = -2;204 $http.post($scope.serverMonitoring+'monitoring.query?callback=addProbeConfig&probeUID='+$scope.probeSelected.probe_uid, $scope.newProbeConfig).then(205 function(response){206 $scope.refresh();207 });208 };209 $scope.updateProbeConfig = function (){210 $http.post($scope.serverMonitoring+'monitoring.query?callback=updateProbeConfig', $scope.probeConfigSelected).then(211 function(response){212 $scope.refresh();213 });214 };215 $scope.rmProbeConfig = function (){216 if($scope.probeConfigSelected_uid){217 $http.get($scope.serverMonitoring+'monitoring.query?callback=rmProbeConfig&probeConfigUID='+$scope.probeConfigSelected_uid).then(218 function(response){219 $scope.probeConfigSelected_uid = -1;220 $scope.refresh();221 });222 }223 };224 $scope.addProbeAcquMode = function (){225 $scope.probeAcquMode.concat($scope.newProbeAcquMode);226 $scope.probeAcquModeSelected = $scope.newProbeAcquMode;227 $scope.probeAcquModeSelected_uid = $scope.probeAcquModeSelected.probe_acqu_mode_uid;228 $http.post($scope.serverMonitoring+'monitoring.query?callback=addProbeAcquMode', $scope.newProbeAcquMode).then(229 function(response){230 $scope.refresh();231 });232 };233 $scope.updateProbeAcquMode = function (){234 $http.post($scope.serverMonitoring+'monitoring.query?callback=updateProbeAcquMode', $scope.probeAcquModeSelected).then(235 function(response){236 $scope.refresh();237 });238 };239 $scope.rmProbeAcquMode = function (){240 if($scope.probeAcquModeSelected_uid){241 $http.get($scope.serverMonitoring+'monitoring.query?callback=rmProbeAcquMode&probeAcquModeUID='+$scope.probeAcquModeSelected_uid).then(242 function(response){243 $scope.probeAcquModeSelected_uid = -1;244 $scope.refresh();245 });246 }247 };248 //////////////////////////////////////////249 // Method on user input 250 //////////////////////////////////////////251 $scope.onSelectProbe = function(){252 var item = $scope.probes[0];253 for (var i = 0, item; item = $scope.probes[i]; i++) {254 if($scope.probeSelected_uid === item.probe_uid){255 $scope.probeSelected = item;256 }257 }258 $scope.getProbeConfig($scope.probeSelected_uid);259 };260 $scope.onSelectProbeConfig = function(){261 var item = $scope.probeConfig[0];262 for (var i = 0, item; item = $scope.probeConfig[i]; i++) {263 if($scope.probeConfigSelected_uid === item.probe_config_uid){264 $scope.probeConfigSelected = $scope.probeConfig[i];265 }266 }267 for (var i = 0, item; item = $scope.probeAcquMode[i]; i++) {268 if($scope.probeConfigSelected.probe_acqu_mode_uid === item.probe_acqu_mode_uid){269 $scope.probeAcquModeSelected = $scope.probeAcquMode[i];270 $scope.probeAcquModeSelected_uid = item.probe_acqu_mode_uid;271 }272 }273 };274 $scope.onSelectProbeAcquMode = function(){275 Monitoring.linkAcquModeToConfig($scope.probeAcquModeSelected_uid, $scope.probeConfigSelected_uid);276 var item = $scope.probeAcquMode[0];277 for (var i = 0, item; item = $scope.probeAcquMode[i]; i++) {278 if($scope.probeAcquModeSelected_uid === item.probe_acqu_mode_uid){279 $scope.probeAcquModeSelected = $scope.probeAcquMode[i];280 }281 }282 };283 //////////////////////////////////////////284 // DEBUG function285 //////////////////////////////////////////286 $scope.debug = function (){287 console.log($scope.probeSelected);288 };289 //////////////////////////////////////////290 //Call method to init display291 //////////////////////////////////////////292 $scope.refresh=function(){293 $scope.getProbes();294 // $scope.getProbeAcquMode();295 };296 $scope.initProbesList();297 $scope.initProbeConfigList();298 $scope.initProbeAcquModeList();299 $scope.refresh();300}]);301myAppCtrl.controller('ProbesManagementCtrl', 302 ['Monitoring', 'socket', '$scope', '$http', 303 function(Monitoring, socket, $scope, $http ) {304 //////////////////////////////////////////305 // Init methods306 //////////////////////////////////////////307 $scope.serverMonitoring = "http://localhost:8000/";308 $scope.initProbesManagementList = function(){309 $scope.probeManagementSelected_uid = -1;310 $scope.probeManagementSelected_uid = null;311 $scope.probesManagement = [];312 };313 socket.on('refreshProbes', function(data){314 $scope.refresh();315 });316 $scope.getProbesManagement = function (){317 Monitoring.getProbesManagement()318 .then(function(data){319 $scope.probesManagement = data;320 $scope.probeManagementSelected = $scope.probesManagement[0];321 },322 function(){323 $scope.initProbesManagementList();324 });325 };326 $scope.onClickProbeStatus = function (probe_uid, probe_config_uid, status){327 var data = {328 'probe_uid': probe_uid,329 'probe_config_uid': probe_config_uid,330 'status':!status331 };332 $http.post($scope.serverMonitoring+'monitoring.query?callback=changeProbeStatus', data).then(333 function(response){334 $scope.refresh();335 });336 };337 //////////////////////////////////////////338 //Call method to init display339 //////////////////////////////////////////340 $scope.refresh=function(){341 $scope.getProbesManagement();342 };343 $scope.initProbesManagementList();344 $scope.refresh();345}]);346myAppCtrl.controller('AdminServerCtrl', 347 ['Monitoring', 'socket', '$scope', '$http', '$location', 348 function(Monitoring, socket, $scope, $http, $location ) {349 //////////////////////////////////////////350 // Init methods351 //////////////////////////////////////////352 $scope.config = {};353 Monitoring.getConfig()354 .then(function(data){355 if(data){356 $scope.config = data;357 }358 });359 $scope.onCreateDB=function(){360 $http.get('/monitoring.query?callback=createDB').then(361 function(){362 $scope.serverConnected = true;363 $location.path("/admin_probes");364 });365 };366 367 $scope.onChangeConfigDB=function(){368 Monitoring.setConfig($scope.config)369 .then(function(){370 $scope.serverConnected = true;371 $location.path("/monitoring");372 })373 .catch(function(err){374 $scope.serverConnected = false;375 });376 };...
ProbeManager.js
Source:ProbeManager.js
1/*2 * Copyright (C) 2013 University of Washington. All rights reserved.3 * Copyright (C) 2014 Apple Inc. All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions7 * are met:8 * 1. Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 * 2. Redistributions in binary form must reproduce the above copyright11 * notice, this list of conditions and the following disclaimer in the12 * documentation and/or other materials provided with the distribution.13 *14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS15 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A17 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT18 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25 */26WebInspector.ProbeManager = class ProbeManager extends WebInspector.Object27{28 constructor()29 {30 super();31 // Used to detect deleted probe actions.32 this._knownProbeIdentifiersForBreakpoint = new Map;33 // Main lookup tables for probes and probe sets.34 this._probesByIdentifier = new Map;35 this._probeSetsByBreakpoint = new Map;36 WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.BreakpointAdded, this._breakpointAdded, this);37 WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.BreakpointRemoved, this._breakpointRemoved, this);38 WebInspector.Breakpoint.addEventListener(WebInspector.Breakpoint.Event.ActionsDidChange, this._breakpointActionsChanged, this);39 // Saved breakpoints should not be restored on the first event loop turn, because it40 // makes manager initialization order very fragile. No breakpoints should be available.41 console.assert(!WebInspector.debuggerManager.breakpoints.length, "No breakpoints should exist before all the managers are constructed.");42 }43 // Public44 get probeSets()45 {46 return [...this._probeSetsByBreakpoint.values()];47 }48 probeForIdentifier(identifier)49 {50 return this._probesByIdentifier.get(identifier);51 }52 // Protected (called by WebInspector.DebuggerObserver)53 didSampleProbe(sample)54 {55 console.assert(this._probesByIdentifier.has(sample.probeId), "Unknown probe identifier specified for sample: ", sample);56 var probe = this._probesByIdentifier.get(sample.probeId);57 var elapsedTime = WebInspector.timelineManager.computeElapsedTime(sample.timestamp);58 probe.addSample(new WebInspector.ProbeSample(sample.sampleId, sample.batchId, elapsedTime, sample.payload));59 }60 // Private61 _breakpointAdded(breakpointOrEvent)62 {63 var breakpoint;64 if (breakpointOrEvent instanceof WebInspector.Breakpoint)65 breakpoint = breakpointOrEvent;66 else67 breakpoint = breakpointOrEvent.data.breakpoint;68 console.assert(breakpoint instanceof WebInspector.Breakpoint, "Unknown object passed as breakpoint: ", breakpoint);69 if (this._knownProbeIdentifiersForBreakpoint.has(breakpoint))70 return;71 this._knownProbeIdentifiersForBreakpoint.set(breakpoint, new Set);72 this._breakpointActionsChanged(breakpoint);73 }74 _breakpointRemoved(event)75 {76 var breakpoint = event.data.breakpoint;77 console.assert(this._knownProbeIdentifiersForBreakpoint.has(breakpoint));78 this._breakpointActionsChanged(breakpoint);79 this._knownProbeIdentifiersForBreakpoint.delete(breakpoint);80 }81 _breakpointActionsChanged(breakpointOrEvent)82 {83 var breakpoint;84 if (breakpointOrEvent instanceof WebInspector.Breakpoint)85 breakpoint = breakpointOrEvent;86 else87 breakpoint = breakpointOrEvent.target;88 console.assert(breakpoint instanceof WebInspector.Breakpoint, "Unknown object passed as breakpoint: ", breakpoint);89 // Sometimes actions change before the added breakpoint is fully dispatched.90 if (!this._knownProbeIdentifiersForBreakpoint.has(breakpoint)) {91 this._breakpointAdded(breakpoint);92 return;93 }94 var knownProbeIdentifiers = this._knownProbeIdentifiersForBreakpoint.get(breakpoint);95 var seenProbeIdentifiers = new Set;96 breakpoint.probeActions.forEach(function(probeAction) {97 var probeIdentifier = probeAction.id;98 console.assert(probeIdentifier, "Probe added without breakpoint action identifier: ", breakpoint);99 seenProbeIdentifiers.add(probeIdentifier);100 if (!knownProbeIdentifiers.has(probeIdentifier)) {101 // New probe; find or create relevant probe set.102 knownProbeIdentifiers.add(probeIdentifier);103 var probeSet = this._probeSetForBreakpoint(breakpoint);104 var newProbe = new WebInspector.Probe(probeIdentifier, breakpoint, probeAction.data);105 this._probesByIdentifier.set(probeIdentifier, newProbe);106 probeSet.addProbe(newProbe);107 return;108 }109 var probe = this._probesByIdentifier.get(probeIdentifier);110 console.assert(probe, "Probe known but couldn't be found by identifier: ", probeIdentifier);111 // Update probe expression; if it differed, change events will fire.112 probe.expression = probeAction.data;113 }, this);114 // Look for missing probes based on what we saw last.115 knownProbeIdentifiers.forEach(function(probeIdentifier) {116 if (seenProbeIdentifiers.has(probeIdentifier))117 return;118 // The probe has gone missing, remove it.119 var probeSet = this._probeSetForBreakpoint(breakpoint);120 var probe = this._probesByIdentifier.get(probeIdentifier);121 this._probesByIdentifier.delete(probeIdentifier);122 knownProbeIdentifiers.delete(probeIdentifier);123 probeSet.removeProbe(probe);124 // Remove the probe set if it has become empty.125 if (!probeSet.probes.length) {126 this._probeSetsByBreakpoint.delete(probeSet.breakpoint);127 probeSet.willRemove();128 this.dispatchEventToListeners(WebInspector.ProbeManager.Event.ProbeSetRemoved, {probeSet});129 }130 }, this);131 }132 _probeSetForBreakpoint(breakpoint)133 {134 if (this._probeSetsByBreakpoint.has(breakpoint))135 return this._probeSetsByBreakpoint.get(breakpoint);136 var newProbeSet = new WebInspector.ProbeSet(breakpoint);137 this._probeSetsByBreakpoint.set(breakpoint, newProbeSet);138 this.dispatchEventToListeners(WebInspector.ProbeManager.Event.ProbeSetAdded, {probeSet: newProbeSet});139 return newProbeSet;140 }141};142WebInspector.ProbeManager.Event = {143 ProbeSetAdded: "probe-manager-probe-set-added",144 ProbeSetRemoved: "probe-manager-probe-set-removed",...
ProbeDetailsSidebarPanel.js
Source:ProbeDetailsSidebarPanel.js
1/*2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved.3 * Copyright (C) 2013 University of Washington. All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions7 * are met:8 * 1. Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 * 2. Redistributions in binary form must reproduce the above copyright11 * notice, this list of conditions and the following disclaimer in the12 * documentation and/or other materials provided with the distribution.13 *14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS15 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A17 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT18 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25 */26WebInspector.ProbeDetailsSidebarPanel = class ProbeDetailsSidebarPanel extends WebInspector.DetailsSidebarPanel27{28 constructor()29 {30 super("probe", WebInspector.UIString("Probes"), WebInspector.UIString("Probes"));31 WebInspector.probeManager.addEventListener(WebInspector.ProbeManager.Event.ProbeSetAdded, this._probeSetAdded, this);32 WebInspector.probeManager.addEventListener(WebInspector.ProbeManager.Event.ProbeSetRemoved, this._probeSetRemoved, this);33 this._probeSetSections = new Map;34 this._inspectedProbeSets = [];35 // Initialize sidebar sections for probe sets that already exist.36 for (var probeSet of WebInspector.probeManager.probeSets)37 this._probeSetAdded(probeSet);38 }39 // Public40 get inspectedProbeSets()41 {42 return this._inspectedProbeSets.slice();43 }44 set inspectedProbeSets(newProbeSets)45 {46 for (var probeSet of this._inspectedProbeSets) {47 var removedSection = this._probeSetSections.get(probeSet);48 this.contentElement.removeChild(removedSection.element);49 }50 this._inspectedProbeSets = newProbeSets;51 for (var probeSet of newProbeSets) {52 var shownSection = this._probeSetSections.get(probeSet);53 this.contentElement.appendChild(shownSection.element);54 }55 }56 inspect(objects)57 {58 if (!(objects instanceof Array))59 objects = [objects];60 var inspectedProbeSets = objects.filter(function(object) {61 return object instanceof WebInspector.ProbeSet;62 });63 inspectedProbeSets.sort(function sortBySourceLocation(aProbeSet, bProbeSet) {64 var aLocation = aProbeSet.breakpoint.sourceCodeLocation;65 var bLocation = bProbeSet.breakpoint.sourceCodeLocation;66 var comparisonResult = aLocation.sourceCode.displayName.localeCompare(bLocation.sourceCode.displayName);67 if (comparisonResult !== 0)68 return comparisonResult;69 comparisonResult = aLocation.displayLineNumber - bLocation.displayLineNumber;70 if (comparisonResult !== 0)71 return comparisonResult;72 return aLocation.displayColumnNumber - bLocation.displayColumnNumber;73 });74 this.inspectedProbeSets = inspectedProbeSets;75 return !!this._inspectedProbeSets.length;76 }77 // Private78 _probeSetAdded(probeSetOrEvent)79 {80 var probeSet;81 if (probeSetOrEvent instanceof WebInspector.ProbeSet)82 probeSet = probeSetOrEvent;83 else84 probeSet = probeSetOrEvent.data.probeSet;85 console.assert(!this._probeSetSections.has(probeSet), "New probe group ", probeSet, " already has its own sidebar.");86 var newSection = new WebInspector.ProbeSetDetailsSection(probeSet);87 this._probeSetSections.set(probeSet, newSection);88 }89 _probeSetRemoved(event)90 {91 var probeSet = event.data.probeSet;92 console.assert(this._probeSetSections.has(probeSet), "Removed probe group ", probeSet, " doesn't have a sidebar.");93 // First remove probe set from inspected list, then from mapping.94 var inspectedProbeSets = this.inspectedProbeSets;95 var index = inspectedProbeSets.indexOf(probeSet);96 if (index !== -1) {97 inspectedProbeSets.splice(index, 1);98 this.inspectedProbeSets = inspectedProbeSets;99 }100 var removedSection = this._probeSetSections.get(probeSet);101 this._probeSetSections.delete(probeSet);102 removedSection.closed();103 }...
Using AI Code Generation
1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test submitted to WebPageTest! Polling for results...');5 wpt.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('Test completed!');8 console.log(data);9 });10});11var WebPageTest = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) return console.error(err);14 console.log('Test submitted to WebPageTest! Polling for results...');15 wpt.getTestResults(data.data.testId, function(err, data) {16 if (err) return console.error(err);17 console.log('Test completed!');18 console.log(data);19 });20});21var WebPageTest = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) return console.error(err);24 console.log('Test submitted to WebPageTest! Polling for results...');25 wpt.getTestResults(data.data.testId, function(err, data) {26 if (err) return console.error(err);27 console.log('Test completed!');28 console.log(data);29 });30});31var WebPageTest = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33 if (err) return console.error(err);34 console.log('Test submitted to WebPageTest! Polling for results...');35 wpt.getTestResults(data.data.testId, function(err, data) {36 if (err) return console.error(err);37 console.log('Test completed!');38 console.log(data);39 });40});
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org', 'A.5f8e5c5c9b5f5d5e4f8b5e5c5e5e5f5e');2var options = {3};4wpt.runTest(url, options, function(err, data) {5 if (err) return console.error(err);6 console.log('Test status: ' + data.statusText);7 console.log('Test ID: ' + data.data.testId);8 console.log('Test URL: ' + data.data.summary);9 console.log('Test results: ' + data.data.userUrl);10 console.log('Test video: ' + data.data.videoUrl);11 console.log('Test json: ' + data.data.jsonUrl);12 console.log('Test xml: ' + data.data.xmlUrl);13});
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3var options = {4};5client.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted. Polling for results...');8 client.waitForTestComplete(data.data.testId, function(err, result) {9 if (err) return console.error(err);10 console.log('First View');11 console.log(' Speed Index: %d', result.data.average.firstView.SpeedIndex);12 console.log(' TTFB: %d', result.data.average.firstView.TTFB);13 console.log(' Start Render: %d', result.data.average.firstView.render);14 console.log(' Fully Loaded: %d', result.data.average.firstView.fullyLoaded);15 console.log(' Doc Complete: %d', result.data.average.firstView.docTime);16 console.log(' Load Time: %d', result.data.average.firstView.loadTime);17 console.log(' Bytes In: %d', result.data.average.firstView.bytesIn);18 console.log(' Bytes In Doc: %d', result.data.average.firstView.bytesInDoc);19 console.log(' Bytes Out: %d', result.data.average.firstView.bytesOut);20 console.log(' Bytes Out Doc: %d', result.data.average.firstView.bytesOutDoc);21 console.log(' Connections: %d', result.data.average.firstView.connections);22 console.log(' Requests: %d', result.data.average.firstView.requests);23 console.log(' Requests Doc: %d', result.data.average.firstView.requestsDoc);24 console.log(' Responses 200: %d', result.data.average.firstView.responses_200);25 console.log(' Responses 404: %d', result.data.average.firstView.responses_404);26 console.log(' Responses Other: %d', result.data.average.firstView.responses_other);27 });28});29var wpt = require('webpagetest');30var client = wpt('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('wpt');2wpt.getLocations(function(err, data){3 if(err){4 console.log('Error: ' + err);5 return;6 }7 console.log(data);8});9var wpt = require('wpt');10 if(err){11 console.log('Error: ' + err);12 return;13 }14 console.log(data);15});16var wpt = require('wpt');17var testOptions = {18};19wpt.test(testOptions, function(err, data){20 if(err){21 console.log('Error: ' + err);22 return;23 }24 console.log(data);25});26var wpt = require('wpt');27var testOptions = {28};29wpt.test(testOptions, function(err, data){30 if(err){31 console.log('Error: ' + err);32 return;33 }34 console.log(data);35});36var wpt = require('wpt');37var testOptions = {38};39wpt.test(testOptions, function(err, data){40 if(err){41 console.log('Error: ' + err);42 return;43 }44 console.log(data);45});46var wpt = require('wpt');47var testOptions = {48 videoParams: {
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5b0e5b5e4b1d0b8c4e4fb4c4b4c4b4c4');3 if (err) return console.log(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.log(err);6 console.log(data);7 });8});9{10 "scripts": {11 },12 "repository": {
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3 videoParams: {4 },5 timelineParams: {6 },7 lighthouseParams: {8 'throttling': {9 }10 }11};12var webPageTest = new wpt('www.webpagetest.org', options);13 if (err) return console.log(err);14 console.log('Test ID: %s', data.data.testId);15 webPageTest.getTestResults(data.data.testId, function(err, data) {16 if (err) return console.log(err);17 console.log('Test Complete');18 console.log('First View (ms): %s', data.data.average.firstView.loadTime);19 console.log('First View (ms): %s', data.data.average.firstView.TTFB);20 console.log('First View (ms): %s', data.data.average.firstView.render);21 console.log('First View (ms): %s', data.data.average.firstView.SpeedIndex);22 console.log('First View (ms): %s
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!