~stolowski/unity-scope-home/phone-disable-filters

« back to all changes in this revision

Viewing changes to tests/unit/test-home-scope.vala

  • Committer: Pawel Stolowski
  • Date: 2013-09-30 12:33:38 UTC
  • Revision ID: pawel.stolowski@canonical.com-20130930123338-6kl28xnx3825t506
Verify filter values in test_phone_filters and test_desktop_filters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
      // ignore warnings
193
193
      Test.log_set_fatal_handler (() => { return false; });
194
194
 
 
195
      bool got_filters_update = false;
 
196
 
195
197
      var proxy = acquire_test_proxy (HOME_SCOPE_DBUS_NAME, HOME_SCOPE_DBUS_PATH);
196
198
      var channel_id = open_channel (proxy, ChannelType.GLOBAL, null);
197
199
      
198
200
      assert (channel_id != null);
 
201
 
 
202
      proxy.filter_settings_changed.connect ((chid, filter_rows) => {
 
203
          got_filters_update = true;
 
204
      });      
199
205
      
200
206
      var hints = new HashTable<string, Variant> (str_hash, str_equal);
201
207
      hints["form-factor"] = "phone";
202
208
      perform_search (proxy, channel_id, "metallica", hints, null);
 
209
 
 
210
      assert (got_filters_update == false); // we expect no filter updates on the phone
203
211
    }
204
212
 
205
213
    internal void test_desktop_filters ()
207
215
      // ignore warnings
208
216
      Test.log_set_fatal_handler (() => { return false; });
209
217
 
 
218
      int got_filters_update = 0;
 
219
 
210
220
      var proxy = acquire_test_proxy (HOME_SCOPE_DBUS_NAME, HOME_SCOPE_DBUS_PATH);
211
221
      var channel_id = open_channel (proxy, ChannelType.GLOBAL, null);
212
 
      
 
222
 
 
223
      Variant? filters = null;
 
224
      proxy.filter_settings_changed.connect ((chid, filter_rows) => {
 
225
          got_filters_update += 1;
 
226
          // note: there are 2 filter updates during search, but we care about the final value of filters
 
227
          filters = filter_rows;
 
228
      });
 
229
    
213
230
      assert (channel_id != null);
 
231
      assert (got_filters_update == 0);
214
232
      
 
233
      // verify all filter options are initially inactive
 
234
      int option_count = 0;
 
235
      for (var iter = proxy.filters_model.get_first_iter (); iter != proxy.filters_model.get_last_iter (); iter = proxy.filters_model.next (iter))
 
236
      {
 
237
        var opts = proxy.filters_model.get_row (iter)[4].lookup_value ("options", null);
 
238
        for (int i = 0; i<opts.n_children (); i++)
 
239
        {
 
240
          option_count += 1;
 
241
          var opt = opts.get_child_value(i);
 
242
          assert (opt.get_child_value (3).get_boolean () == false);
 
243
          print ("%s ", opt.get_child_value (0).get_string());
 
244
        }
 
245
      }
 
246
 
 
247
      assert (proxy.filters_model.get_n_rows () == 2);
 
248
      assert (option_count == 17);
 
249
 
215
250
      var hints = new HashTable<string, Variant> (str_hash, str_equal);
216
251
      hints["form-factor"] = "desktop";
217
252
      perform_search (proxy, channel_id, "iron maiden", hints, null);
218
253
 
219
 
      hints.foreach ((k,v) => {
220
 
          print ("%s: %s", k, v.print(true));
221
 
        });
 
254
      assert (got_filters_update == 2);
 
255
      assert (filters.n_children() == 2); // two filters ('sources' and 'categories')
 
256
      var src_filter = filters.get_child_value(0);
 
257
      var cat_filter = filters.get_child_value(1);
 
258
      
 
259
      // verify 'sources' filter
 
260
      var opts = src_filter.get_child_value (4).lookup_value ("options", null);
 
261
      var option_flags = new HashTable<string, bool>(str_hash, str_equal);
 
262
 
 
263
      for (int i = 0; i<opts.n_children (); i++) // create scopeid -> enabled flag lookup for sources filter
 
264
      {
 
265
          var opt = opts.get_child_value(i);
 
266
          option_flags[opt.get_child_value (0).get_string ()] = opt.get_child_value (3).get_boolean ();
 
267
      }
 
268
 
 
269
      assert (option_flags["reference-stackexchange.scope"] == false);
 
270
      assert (option_flags["reference-dictionary.scope"] == false);
 
271
      assert (option_flags["reference-themoviedb.scope"] == false);
 
272
      assert (option_flags["masterscope_b-subscope1.scope"] == false);
 
273
      assert (option_flags["masterscope_b-subscope2.scope"] == false);
 
274
      assert (option_flags["masterscope_a-subscope1.scope"] == false);
 
275
      assert (option_flags["masterscope_a-subscope2.scope"] == false);
 
276
      assert (option_flags["more_suggestions-amazon.scope"] == false);
 
277
      assert (option_flags["more_suggestions-etsy.scope"] == false);
 
278
      assert (option_flags["more_suggestions-ebay.scope"] == false);
 
279
      assert (option_flags["more_suggestions-skimlinks.scope"] == false);
 
280
      
 
281
      assert (option_flags["more_suggestions-u1ms.scope"] == true);
 
282
      assert (option_flags["reference-wikipedia.scope"] == true);
 
283
 
 
284
      // verify 'categories' filter
 
285
      opts = cat_filter.get_child_value (4).lookup_value ("options", null);
 
286
      option_flags = new HashTable<string, bool>(str_hash, str_equal);
 
287
 
 
288
      for (int i = 0; i<opts.n_children (); i++) // create scopeid -> enabled flag lookup for categories filter
 
289
      {
 
290
          var opt = opts.get_child_value(i);
 
291
          option_flags[opt.get_child_value (0).get_string ()] = opt.get_child_value (3).get_boolean ();
 
292
      }
 
293
      
 
294
      assert (option_flags["masterscope_a.scope"] == false);
 
295
      assert (option_flags["masterscope_b.scope"] == false);
 
296
 
 
297
      assert (option_flags["more_suggestions.scope"] == true);
 
298
      assert (option_flags["reference.scope"] == true);
222
299
    }
223
300
  }
224
301